Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
1
Question by adibazhar · Sep 21, 2017 at 03:05 AM · boardgame

Movement based on dice

Hello..i am working on a board game like monopoly. How can i movement the player based on the number got from the dice/die.

Comment
Add comment · Show 2
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 adibazhar · Oct 04, 2017 at 01:34 PM 0
Share

@tmalhassan im making it in 3D. i already get the logic and algo but what the problem is the moveDistance (how many square the player will move ) always changing per second. But before we go far i am wonder if my method to get the dice result using this code is suitable or there is other ways ?

public class diceCheckZoneScript : $$anonymous$$onoBehaviour {

 Vector3 diceVelocity;
 public static int moveDistance = 0;


 void FixedUpdate () {
     diceVelocity = dicescript.diceVelocity;
 }

 void OnTriggerStay(Collider col)
 {

     //if (dicescript.diceTrigger == true) {
         
             if (diceVelocity.x == 0f && diceVelocity.y == 0f && diceVelocity.z == 0f) {
                 switch (col.gameObject.name) {
                 case "side1":
                     DiceNumberTextScript.diceNumber = 6;
                 
                     break;
                 case "side2":
                     DiceNumberTextScript.diceNumber = 5;

                     break;
                 case "side3":
                     DiceNumberTextScript.diceNumber = 4;
                 
                     break;
                 case "side4":
                     DiceNumberTextScript.diceNumber = 3;
                 
                     break;
                 case "side5":
                     DiceNumberTextScript.diceNumber = 2;
                 
                     break;
                 case "side6":
                     DiceNumberTextScript.diceNumber = 1;
                 
                     break;
                 }

             } 
         //}

 }

avatar image tmalhassan adibazhar · Oct 04, 2017 at 03:11 PM 0
Share

The script that you posted doesn't help at all. Okay, it's a 3D game. On which orientation does the player move? X, Y or Z? And how are you moving the player? do you have a script for that? you need to explain things in details in order for us to help. Right now, every thing seems vague.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · Oct 04, 2017 at 06:10 PM

i was bored so i wrote a script that gives the dice number everytime the dice stops. attach this to your dice. all you need to do is change the order of the directions to represent wherever the real dice numbers are.

     public float sensitivity=200;
     float oldx,oldz,oldy;
     int time,skipframe;
 
     void Update(){
 
         skipframe++;
         if(skipframe>10){skipframe=0;
           if(Mathf.Round(oldx*sensitivity)==Mathf.Round(transform.position.x*sensitivity)
            &&Mathf.Round(oldy*sensitivity)==Mathf.Round(transform.position.y*sensitivity)
            &&Mathf.Round(oldz*sensitivity)==Mathf.Round(transform.position.z*sensitivity))
             {time++;}else{time=0;}
             oldx=transform.position.x;
             oldy=transform.position.y;
             oldz=transform.position.z;
             if(time==20){print("side up is"+getup());}
 }}
 
     int getup(){
 
         float sence=2;
         int i;
         int side=0;
                                 //put these in correct order for dice numbers
         Vector3[] ds = new Vector3[] {transform.up,-transform.up,
                                       transform.right,-transform.right,
                                       transform.forward,-transform.forward};
         i = ds.Length;
             while (i>0) {i--;
             if(Mathf.Round(ds[i].x*sence)==Vector3.up.x*sence){
             if(Mathf.Round(ds[i].y*sence)==Vector3.up.y*sence){
             if(Mathf.Round(ds[i].z*sence)==Vector3.up.z*sence){
             side=i+1;i=0;
                     }}}}
         if(side==0){print("oops....i didn't find side");}
         return side;
     
 }
Comment
Add comment · Show 1 · 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
avatar image OfficialCrimsonGames · Aug 18, 2020 at 10:34 AM 0
Share

I know this is an old forum and may not be answered, but I am new to Unity, like 2 weeks new. I have no scripting knowledge in C# only Lua. I have my game created and so far so good except the dice roll. I can roll the die but of course its not scripted. How could I implement a script like this into a D10 die so our characters move the correct number of spaces?

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

71 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Building a Chessboard 2 Answers

VR games using cardboard 0.7 are not showing in playstore on devices which donot have gyro sensor.. 0 Answers

Creating a mahjong game, problem with randomizing tiles and counting points. 1 Answer

How do you create and control a proper turn manager? 0 Answers

Using a switch statement to set tile type based on texture. 1 Answer


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