Hi!
I have a 3D cube and i currently apply force on it so it can auto-rotate using physics 3D (in order to move it like a dice which never leave the ground).
I can move it on the X and Z axis this way. But i have a little problem…i want to force it so it move in the direction it is facing. (Like a wheel but its a cube) Right now i have been able to apply force horizontally and vertically but the problem i am facing is when we move the cube it can go diagonally which i want to avoid because it is difficult to move a cube this way. It should move on his vertex.
How i can achieve that ? I am a bit desesperate.
Thanks a lots!

You can use the AddTorque function for that:
rigidbody.AddRelativeTorque(axis*strength);
Thanks a lots for your help! This work better than applying a force. Actually it do exactly what i wanted it to do. There one problem left through… if the cube fall on its side it will spin like “bacon dance” because axes will have been rotated. Any ideas ?
I am not sure what you mean. But if you mean that the cube keeps spinning even if it can not move any more, you could solve the problem by computing how fast the cube moved in the last 0.5f seconds and if that value drops below 0.2f( or something like that) stop applying torque to the cube.
Example code:
public float strength=0;
public float minSpeed=0.2f;
public bool applyTorque;
Vector3 lastImportantPosition;
void Start()
{
applyTorque = true;
StartCoroutine ("CheckSpeed");
}
IEnumerator CheckSpeed()
{
while (true) {
yield return new WaitForSeconds (0.5f);
if ((transform.position - lastImportantPosition).magnitude < minSpeed) {
applyTorque = false;
}
lastImportantPosition = transform.position;
}
}
void FixedUpdate () {
if (applyTorque) {
rigidbody.AddRelativeTorque (Vector3.right * strength);
}
}