how to move a gameobject based on a dice roll
How would i make a gameobject move based on a dice roll? I am making a virtual board game and after the dice rolls i want the piece to move that far or the player can choose how far they move for example if a six is rolled the player can move 1 to 6 units.
Answer by Avanak · Aug 19, 2016 at 12:57 PM
First use Random.Range(1, 7) and use Mathf.Floor to round the values down to whole numbers.
You can then decide on a value in between the random value and 1 and store it in a variable (let's call this variable moveDistance).
Then use transfom.Translate(Vector3.Direction * moveDistance), Where (Vector3.Direction is the direction you want to move to i.e. Vector3.Forward).
transform.Translate moves the gameObject immediately, if you want to make it move to the destination with a certain speed use the following in the Update() function:
transform.position = Vector3.MoveTowards(transform.position, destination, moveSpeed * Time.deltaTime);
This is some pretty basic stuff and you should be able to find out how each of these things work by googling them.