0 votes

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.

Thanks in advance!

in Engine by (162 points)

1 Answer

+1 vote

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

Node2Dtomove may need

export(NodePath) var path_to_PathFollow

to be able to move it (just tween the offset/unit_offset).

by (7,888 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.