For the first time I am developing something in 3d and with physics. I am following a tutorial to roll a dice.
When I press the button the dices shoots up in the air and roll.
It works well when I have two dices but when I add #3 and #4 those dices goes far up in higher speed. I do not understand what I am doing wrong here.
The dices looks like this:
The following is the code that I have on the four dices:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DiceScript : MonoBehaviour
{
static Rigidbody rb;
public static Vector3 diceVelocity;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
public void RollTheDice ()
{
DiceNumberTextScript.diceNumber = 0;
float dirX = Random.Range(0, 500);
float dirY = Random.Range(0, 500);
float dirZ = Random.Range(0, 500);
transform.position = new Vector3(0, 2, 0);
transform.rotation = Quaternion.identity;
rb.AddForce(transform.up * 1000);
rb.AddTorque(dirX, dirY, dirZ);
}
}
I would appreciate some help so I understand. I have tried to google etc. but still do not understand.