+1 vote

I making a mario party game style, and wanted to know if there is a way to use the Path2d points we use to create the path as localization, or i will need to do a lot of math to move it.

The idea is, the player press the accept button, so it gives a random number that will be how many times it move from one point to the next one, is like thwroing a dice

in Engine by (15 points)

1 Answer

0 votes

I know this is sort of an old post, but I'll answer anyway if somebody else finding this question from Google comes here.

I suggest that you make a Path2D going along with the game-board. Then you slide the Path-node's offset so the moving character is on the point and write down what is the offset of every point in the game-board.

Then make variable, example "var board_point = 0"

then in physics(delta) function: if boardpoint == 1: setoffset(input here the offset you wrote down from point 1), if boardpoint == 2: set_offset(*input here the offset you wrote down from point 2*) and so on...

Then you write the function for dice rolling. In the roll-function: boardpoint += diceroll

For example: Player is in point 2 on game-board, you roll 6 -> board-point=8 -> player goes to offset which is indication on point 8.

Like this player instantly teleports to the point, so you can make extra-variable for counting down the dice-number and use timer to slow down the movement. And going between points you can use Tween-node to make the movement animated.

I made an example:


  • Node2D
    >>Sprite (game-board)
    >>>>Sprite (player)

PathFollow2D code:

extends PathFollow2D

var board_position = 1 #dice roll changes this
var Path_Offset = 0 #this is the offset which board_position puts it in _physics_process

func _physics_process(delta):
    if board_position == 1:
        Path_Offset = 0 #this is the first point and it is on 0 in the path
    if board_position == 2:
        Path_Offset = 438 # this is second point's offset
    if board_position == 3:
        Path_Offset = 860
    if board_position == 4:
        Path_Offset = 1252
    if board_position == 5:
        Path_Offset = 1590
    if board_position == 6:
        Path_Offset = 1845
    if board_position == 7:
        Path_Offset = 2172


    #This is just showing with pressing Enter/Return that the example works
    if Input.is_action_just_pressed("ui_accept"): 
        board_position += 1

Here is video of it working:

by (18 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.