• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Jermainek369 · Aug 18, 2016 at 01:23 PM · scripting problemgameobjectmovementplayer

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help with simple player movement 0 Answers

enemy look at GameObject player? unity ver. 5.2 C# 0 Answers

How can I stop a gameobject movement with timer? 0 Answers

Smooth/realistic crouching script in C#??? 0 Answers

How can I make the camera not overreach a limit of rotation one axis. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges