0 votes

I'm wondering if it's possible to move a character (2D-Scene with a grid/tile-map) based on the result of a RandomNumberGenerator?
The player rolls the dice (onButtonpressed) and gets a random number (let's say: 6).
Is it possible to store that number in a variable so that it can be used for Vector2D-movement on a grid (on_MouseInput)? If so, the player should only be permitted to move 6 tiles up/down/left/right.
How would you solve this?

Godot version Version 3.2.3
in Projects by (17 points)

1 Answer

0 votes

Yes, you can store the result of a random number generator in a variable. As for movement, just limit the distance the end tile can be from the start tile by the randomly generated number times the tile size. What specifically do you need help with?

by (4,476 points)

How would storing the result of the randomly generated number into a Vector2D look like?

You wouldn't store it as a Vector2, you would store it as an int.

Ok, but how would you go on code-wise?
So, I have received my random number (random_number = 6) and want to tell the player that he/she is now allowed to move, for example, 6 fields left/right/up or down.
That's where I'm struggling.

What do you mean, tell the player? Do you want to just display a big number "6" on screen?

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.