Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 $$anonymous$$ · Aug 04, 2014 at 08:15 AM · c#boardgamedice

How to make a Player move to an object using a dice roll

I am trying to make it so when you roll a dice and it lands a 2, you can select 2 spaces in any direction to move to.

Here is a code im using at the moment so that when you roll you move x spaces forward. I need it so you can select where you want to move, the amount of spaces you roll

 public var dieName = "SixSidedDie";
 public var allowedDistance = 0.5;
 private var lastDieValue = 0;
 
 private var target : Transform;
 public var damping = 3.0;
 
 private var dieValueComponent;
 
 public var currentLocation = 1;
 public var targetLocation = 1;
 
 function Start() {
     // cache the dieValueComponent
     dieGameObject = GameObject.Find(dieName);
     dieValueComponent = dieGameObject.GetComponent("DieValue");
     
     // look for the starting position and move there
     tileGameObject = GameObject.Find("tile" + currentLocation.ToString() + "target" );
     transform.position = tileGameObject.transform.position;
     transform.rotation = tileGameObject.transform.rotation;
 }
 
 function Update ()
 {
     if (dieValueComponent.playStarted) {
         // get the new transform if necessary
         // look for a non zero number which means the die has a value
         // block any value that has already been calculated, hence checking last value
         if (lastDieValue != dieValueComponent.currentValue && dieValueComponent.currentValue != 0 && dieValueComponent.turnBegun) {
             targetLocation += dieValueComponent.currentValue;
             currentLocation += 1;
             if (currentLocation > 16) currentLocation = 16;
             if (targetLocation > 16) targetLocaiton = 16;
             tileGameObject = GameObject.Find("tile" + currentLocation.ToString() + "target" );
             target = tileGameObject.transform;
             dieValueComponent.turnBegun = false;
         }
         if (lastDieValue != 0) {
             dist = Vector3.Distance(transform.position, target.position);
             if (dist > allowedDistance) {
                 transform.position = Vector3.Lerp(transform.position, target.position, Time.deltaTime * damping);    
                 transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, Time.deltaTime * damping);    
             }
             else if (currentLocation != targetLocation) {
                 // reset the target
                 currentLocation += 1;
                 if (currentLocation > 16) currentLocation = 16;
                 tileGameObject = GameObject.Find("tile" + currentLocation.ToString() + "target" );
                 target = tileGameObject.transform;
             }
         }
         lastDieValue = dieValueComponent.currentValue;
     }
 }


Comment
Add comment · Show 1
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
avatar image SpazOut · Nov 28, 2016 at 02:26 AM 0
Share

@$$anonymous$$ Did you find an answer to this yet of have you completed your project? If so can you post a link to your game & or tutorial? I'm just getting started on a board game I written years ago & I'm not venturing to video games.

Thanks a lot,

Spaz

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make the 2D board game piece move only when the player answers the question correctly? 0 Answers

Rolling a 3D Dice: Detect which number faces up? 4 Answers

Collider disabling by itself... 2 Answers

How can I change my board game into multi player? 1 Answer

How to create an if statement for each element within a list C# 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges