RigidBody - Adding Force/Torque

Okay i am new to this, trying to make some boxes that works just fine with collisions and such. Thing is, i need to make the jump around a bit from clicking a button, sorta like dices.

I have started on some code, but i run into problem making them move more than just few units or jiggle.

Any help appreciated :slight_smile:

var objDice1: GameObject;
var objDice2: GameObject;
var objDice3: GameObject;
var objDice4: GameObject;

var fFactorTorque = 1000.0;
var fReactionFactor = 1.2;

private var fAccNext = 0.0;
var fAccRate = 0.1;

function OnGUI()
{	
	if (GUI.Button (Rect (25, 25, 100, 30), "Roll dice"))
	{
		var fAcc : Vector3;
		fAcc.x = 3.0;
		fAcc.y = 3.0;
		fAcc.z = 3.0;
		
		objDice1.rigidbody.AddRelativeTorque(fAcc.x * fFactorTorque, fAcc.y * fFactorTorque, fAcc.z * fFactorTorque);
		objDice2.rigidbody.AddRelativeTorque(fAcc.x * fFactorTorque, fAcc.y * fFactorTorque, fAcc.z * fFactorTorque);
		objDice3.rigidbody.AddRelativeTorque(fAcc.x * fFactorTorque, fAcc.y * fFactorTorque, fAcc.z * fFactorTorque);
		objDice4.rigidbody.AddRelativeTorque(fAcc.x * fFactorTorque, fAcc.y * fFactorTorque, fAcc.z * fFactorTorque);
	}
}

Found it out, had to have transform.Translate along with rigidbody.AddForce :slight_smile:

With transform.Translate you bascially bypass the physics engine and you might get strange results with multiple physics object interacting.

You’d have to use rigidbody.AddForce with enough strength to do the same physics-based.

Hi, i’d ilke to do the same to iphone. A dice game.

Could you put an example with your final solution, please?

:-S

Thanks.