Topic was automatically imported from the old Question2Answer platform.
Asked By
HarryCourt
Old Version
Published before Godot 3 was released.
I’m making a monopoly style game and I need to figure out how to make a sprite move to one of the nodes once something happens. If you’re willing to also do some harder work, I need to the PC roll a number, and once the number is rolled (3 for e.g.), I need the sprite to move 3 nodes. Do I need two scripts or can I use one?
I would imagine it like this:
var randomNumber
if Input.is_action_pressed("click"):
move(randomNumber)
#I just quickly made this.
You need to retrieve the Curve2D from the path and get the points (not the baked ones), then tween/move from point to point.
The moving node will need to keep track of where is in the curve (point index).
Another option is to add a PathFollow to move along the path.
I personally don’t like the way PathFollow works because it needs to be child of the path and parent of the node it needs to move, like:
Path2D
|-PathFollow2D
|-Node2D_to_move
I would prefer some decoupling from the path and target node, but is the way it works, at most (without extra coding) you can do:
scene
|-Path2D
| |-PathFollow2D
| |-RemoteTRansform2D (connected to Node2D_to_move)
|-Node2D_to_move
Node2D_to_move may need
export(NodePath) var path_to_PathFollow
to be able to move it (just tween the offset/unit_offset).