- Home /
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.
@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;
}
}
//}
}
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.
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;
}
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

Follow this Question
Related Questions
yield for animation 0 Answers
Board Game Movement 0 Answers
How do you move a character to another waypoint after landing on a specific waypoint 1 Answer
how i can Roll a dice?? 2 Answers
What is the best way to make cards that move game peices 1 Answer