# moveToObject

**URL:** <https://phaser.discourse.group/t/movetoobject/15160>\
**Category:** Phaser 3\
**Created:** [February 19, 2025, 12:15pm UTC](https://phaser.discourse.group/t/movetoobject/15160 "2025-02-19T12:15:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mysticsobindra](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/mysticsobindra/32/8782_2.png) [@mysticsobindra](https://phaser.discourse.group/u/mysticsobindra)\
**Post date:** [February 19, 2025, 12:15pm UTC](https://phaser.discourse.group/t/movetoobject/15160/1 "2025-02-19T12:15:39Z")

</div>

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 .

```javascript

    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

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [February 19, 2025, 5:08pm UTC](https://phaser.discourse.group/t/movetoobject/15160/2 "2025-02-19T17:08:24Z")

</div>

Does the enemy ever move?

---

<div class="post-metadata">

**Author:** ![extreme64](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/extreme64/32/8795_2.png) [@extreme64](https://phaser.discourse.group/u/extreme64)\
**Post date:** [February 23, 2025, 2:30pm UTC](https://phaser.discourse.group/t/movetoobject/15160/3 "2025-02-23T14:30:53Z")

</div>

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