How could I let a container to follow a path as a pathfollower does?

Update 19th Mar:

Luckily, after digging into the API-doc, I found a possible solution and managed to get it run.

That’s to use Phaser.Tweens.Tween and Phaser.Curves.Path, add the container instance as “targets” property of paramter.

Question remaining:

  • Still not sure about the implement of movement in squadron.

I’ll try.


Hi, everyone, glad to post my question here.

I’m a web front-end developer, new to game dev and attracted by Phaser 3.

Current question

  • I could use a path and a follower.
  • But I couldn’t add a container behaves like a follower to follow a path.

Background

  • I’m developing a 2D RTS game demo. Units are vehicles.
  • Like Axis and Allies, Company of Heroes and etc, players operate on squadrons instead of individual units.
  • Squadrons are supposed to roughly keep formation during moving.
  • Squadrons consist of vehicles, and vehicles are made up with turret(s) and body. A turret is composed of barrel(s) and shield.
  • Vehicles have minimal-turning-radius.

Personal implements (pseudo code)

// Squadron, Vehicle, Turret are neither Sprite nor Image. They are Containers, which consist of Sprite or Image.

class Squadron extends Container {
  Vehicles: Array<Vehicle>
  attack()
  retreat()
}

class Vehicle extends Container {
  turrets: Array<Turret>
  body: VehicleBody
  move()
  turn()
}

class Turret extends Container {
  barrels: Array<Barrel>
  shield: Shield
  aimAt()
}

// VehicleBody is Sprite; Barrel and Shield are Image since I don't use animations on them

class VehicleBody extends Sprite {
  MAX_SPEED: number
}

class Barrel extends Image {
  FIRE_RATE: number
  PENETRATION: number
}

class Shield extends Image {
  THICKNESS: number
}

  • I want to use path as squadron movement path.
  • If possible, I also want to ask for your advice to improve my code design above, thanks.
1 Like

Here is my simple path follower behavior, which only provides property t for controlling the position of game object on a path. This path follower behavior does not have tween task.

Here is a demo of this path follower :

  1. Add path follower behavior

    pathFollower = pathFollowerPlugin.add(gameObject, {path: path});
    
  2. Tween pathFollower.t

    scene.tweens.add({
        targets: pathFollower,
        t: 1,
        ease: 'Linear', // 'Cubic', 'Elastic', 'Bounce', 'Back'
        duration: 1000,
        repeat: -1,
        yoyo: true
    });
    

This simple path follower could work with any kind of game object which has properties x, y.

2 Likes

@rexrainbow Thank you for your reply, and your plugin solves my question well. ~\(≧▽≦)/~

Besides, I appreciate your notes of Phaser 3 very much.

1 Like