Godot Version
4.6
Question
I’m making a retro rpg with tile based movement (Astargrid2D) and am struggling to get proper snake/train formation movement working (breathe of fire, dragon warrior 2).
Is there a standard easy way to accomplish this?
func _ready() -> void:
print("hello world")
Where are you stuck? Could you show us your code? Is there a specific problem you cannot get past?
Usual “snake” party trick for tile RPGs:
Don’t path each follower with A*. Only the leader uses AStarGrid2D. Everyone else follows the path the leader already walked.
Here’s a snippet:
var old_positions: Array[Vector2i] = []
# [0] = leader's previous tile, [1] = member0's previous, ...
func on_leader_stepped(prev_tile: Vector2i) -> void:
# shift: last member gets what was in front of them, etc.
for i in range(members.size() - 1, 0, -1):
members[i].move_to_tile(members[i - 1].tile)
members[0].move_to_tile(prev_tile)
Or keep a queue of the leader’s last N tiles and park follower i on history[i].