# Path follower position update

**URL:** <https://phaser.discourse.group/t/path-follower-position-update/12536>\
**Category:** Phaser 3\
**Created:** [November 10, 2022, 4:52pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536 "2022-11-10T16:52:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 4:52pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/1 "2022-11-10T16:52:38Z")

</div>

The x and y coordinate of my path follower stays static throughout the path, I was wondering if there’s a way to update that continuously so I could check the range between it and other sprites etc? Thanks in advance!

---

<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:** [November 10, 2022, 6:14pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/2 "2022-11-10T18:14:46Z")

</div>

Do you mean the path follower `x` and `y` values don’t change while it appears to be moving on the path?

---

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 6:39pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/3 "2022-11-10T18:39:45Z")

</div>

Yes, exactly

---

<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:** [November 10, 2022, 6:50pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/4 "2022-11-10T18:50:52Z")

</div>

And how can you tell?

---

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 7:01pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/5 "2022-11-10T19:01:14Z")

</div>

I’m logging the enemies at half second intervals and the x and y is static

---

<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:** [November 10, 2022, 7:01pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/6 "2022-11-10T19:01:58Z")

</div>

Can you show the scene code?

---

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 7:05pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/7 "2022-11-10T19:05:18Z")

</div>

Sure thing

```javascript
class Game {
  preload() {
    this.load.image('base_tiles', './assets/16x16_Jerom_CC-BY-SA-3.0.png')
    this.load.tilemapTiledJSON('tilemap', './assets/practiceMap.tmj')
    this.load.image('littleFella', 'assets/littleFella.png')
    this.load.image('tower', 'assets/tower.png')
    this.load.image('cannonBall', 'assets/cannonball.png')
  }

  create() {
    //map
    const map = this.make.tilemap({ key: 'tilemap' })
    const tileset = map.addTilesetImage('practiceMap', 'base_tiles')
    map.createLayer('floor', tileset)
    map.createLayer('walls', tileset)

    //sprites
    this.tower = this.physics.add.sprite( 200, 100, 'tower')
    this.tower.setScale(3)

    //fire the canon from the tower
    this.cannonBall = this.physics.add.group()

    //iterate up to total number in enemies group
    this.count = 0

    //shoot count
    this.nextTic = 0

    //creates the path followers
    this.time.addEvent({
      delay: 500,
      callback: () => {
        if (this.count < this.enemies.children.entries.length) {
          this.createLittleFella(this.count)
          this.count++
        }
      },
      loop: 20,
    })

    this.gfx = this.add.graphics();

    this.enemies = this.add.group({runChildUpdate: true });
    this.enemies.create(-40, 32, 'littleFella')
    this.enemies.create(-40, 32, 'littleFella')
    this.enemies.create(-40, 32, 'littleFella')
    this.enemies.create(-40, 32, 'littleFella')
    this.enemies.create(-40, 32, 'littleFella')
    this.enemies.create(-40, 32, 'littleFella')

  }

  update() {
    if(this.time.now > this.nextTic) {
      this.updatePosition()
      this.nextTic = this.time.now + 3000;
    }
  }

  createLittleFella = function(count) {
    let path = new Phaser.Curves.Path(-40, 32)

    path.lineTo(-40, 32)
    path.lineTo(45, 32)
    path.lineTo(45, 465)
    path.lineTo(160, 465)
    path.lineTo(160, 385)
    path.lineTo(110, 385)
    path.lineTo(110, 270)
    path.lineTo(240, 270)
    path.lineTo(240, 370)
    path.lineTo(305, 370)
    path.lineTo(305, 45)
    path.lineTo(450, 45)
    path.lineTo(450, 465)
    path.lineTo(530, 465)

    let mover = this.add.follower(path, -40, 32, this.enemies.children.entries[count].texture.key);
    this.physics.add.existing(mover)

    mover.startFollow({
        positionOnPath: true,
        duration: 10000,
        yoyo: false,
        repeat: 0,
        rotateToPath: false,
        verticalAdjust: true
    });

  
    this.time.addEvent({
      delay: 10500,
      callback: () => {
        mover.destroy()
      },
      loop: 20,
    })

    return mover
  }

  updatePosition = function() {
    var enemyUnits = this.enemies.getChildren();
    if (enemyUnits) {
      for(var i = 0; i < enemyUnits.length; i++) {
          console.log(enemyUnits[i])
      }
    }
  }
  

};

```

---

<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:** [November 10, 2022, 7:28pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/8 "2022-11-10T19:28:01Z")

</div>

The first 6 enemies aren’t followers and won’t be moving, it looks like.

---

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 7:28pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/9 "2022-11-10T19:28:33Z")

</div>

They’re moving when I load it? Like I see them move on the path?

---

<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:** [November 10, 2022, 7:48pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/10 "2022-11-10T19:48:56Z")

</div>

The “enemies” group has 6 sprites that aren’t followers and don’t move. You’re logging these sprites.

There are also 6 “movers” who are followers but they aren’t in the enemies group.

---

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 8:09pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/11 "2022-11-10T20:09:10Z")

</div>

I see. Thank you. Can you help me understand how to make group members follow a path?

---

<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:** [November 10, 2022, 8:15pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/12 "2022-11-10T20:15:56Z")

</div>

Instead of `enemies.create()` you use

```
this.enemies.add(mover);

```

---

<div class="post-metadata">

**Author:** ![phodye](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@phodye](https://phaser.discourse.group/u/phodye)\
**Post date:** [November 10, 2022, 8:43pm UTC](https://phaser.discourse.group/t/path-follower-position-update/12536/13 "2022-11-10T20:43:52Z")

</div>

Thank you for your time! I feel foolish, that solved my issues. Now I just need to figure out how to actually aim.
