moveToObject

here this is enemy and this.player is a player .
i want the enemy to move toward the player when player is in short range .


    EnemyAttack() {
        if (this.shortrange && this.PlayerInZone) {
            console.log('in short range')
            // Move towards the player
            this.scene.physics.moveToObject(this, this.player, 200);
    
            // Check for overlap and perform melee attack
            return this.scene.physics.overlap(this.player, this, () => {
                this.MeeleWeaponAttack();
            });
        } else if (!this.shortrange && this.PlayerInZone) {
            return this.LongRangeAttack();
        }
    }
    
    MeeleWeaponAttack() {
        console.log('melee weapon attack');
    }

both console is seen as expected but enemy doesnot move towards player when in short range

Does the enemy ever move?

1 Like

@mysticsobindra Does code ever flow pass this.shortrange && this.PlayerInZone condition?