How do I move the player on top of a tile one step at a time?

How do I move the player on top of a tile one step at a time?

I am trying to create a snake and ladder game and now I am struggling to move the player one tile at a time whenever the dice is rolled. I have this variable StepsLeft and I want the player to move one tile at a time as long as StepsLeft is not equal to 0. I also have variable tileNumber on each tile and it has an assigned number based on the tile number but I am not sure on how to use it.

What is the expected result

I can see the player to move one tile at a time only as long as the StepsLeft variable is not equal to zero and the player will stop if the StepsLeft is equal to zero.

What is the actual result

After clicking the dice button, my player is stuck and just doesn’t move

Related screenshots

Sorry guys, I am quite new to this platform and game development so I am not familiar

In your last event, you don’t have a condition to select which tile the player should move to.

You could modify your event like this:


However, this will move the player faster than you can see from their current tile to the target tile, even if it’s a few steps away, and it will appear like they have teleported to their destination.

Instead, I’d suggest you use a tween to move the player (remember to add the tween behaviour to the player object first). Something like:

My preferred method would be to use the linked tools behavior. That’s a little more advanced. It requires more setup but then it’s relatively easy to move the objects.

https://wiki.gdevelop.io/gdevelop5/extensions/link-tools/details/

My next favorite method would be to use the tween behavior. I’m not saying this is the best or even flawless. This is just one way. It’s very similar to MrMen’s version.

Add the tween behavior to the player. I used object variables but you can use scene.

Events.

I added the min() expressions to prevent the player from trying to move to an index that doesn’t exist. The player starts on the tile with an ID of zero.

I used a button object for testing.

1 Like

Where does the “Move” variable on Player came from? From your last image, you set a variable on the Player called Moves. I am asking this since I am having a hard time following the Tween “Move” on Player is playing. Is it possible that you have the full snapshot of your event sheet?

It’s cropped a bit but it’s moves. Not move.