Rotate a rigid body while it's constrained.

I’m having an issue rotating a rigidbody. If I constrain it, it looks great, but I can’t turn. If I don’t constrain it, it falls right over. Is there a method I can use to keep it constrained, (so it won’t fall over), and still be capable of rotating it’s Y axis?

Thank you very much for your help. Below is the script. It’s extremely basic at the moment, so I’m not sure how much help it’ll be, but it might.

var speed : float;
var power : float;
var evolution : int;
var vert : float;
var hori : float;

function Start () {

}

function Update () {
vert = Input.GetAxis("Vertical");
hori = Input.GetAxis("Horizontal");

if (vert > 0)
	{
		rigidbody.AddRelativeTorque(Vector3(speed + power, 0, 0), ForceMode.Force);
	}
if (vert < 0)
	{
		rigidbody.AddRelativeTorque(Vector3(-(speed + power), 0, 0), ForceMode.Force);
	}
	
if (hori > .9)
	{
		rigidbody.AddTorque(Vector3(0, 10, 0));
	}
if (hori < -.9)
	{
		rigidbody.AddTorque(Vector3(0, -10, 0));
	}
}

2 Answers

2

Rigidbody.rotation

Transform.Rotate

Transform.localEulerAngles

Only constrain the x and z axis for rotation. There should be checkboxes for this in the inspector for your rigidbody

I can't do it that way. It needs to rotate on the X and Y axis. If I only constrain the Z axis, it falls right over.

–

Ahh, I see. Could you possibly constrain x until you need to rotate, then re-constrain after?

–

No, tried that. It just fell over when I tried to turn. Think of it like a tire. It needs to rotate on the X to move forward, and on the Y to turn. That's where I'm getting my issue, is that the tire itself won't stay up, due to gravity, but whenever I've tried something similar in the past, the constraints on the rigid body just kept it from falling over.

–

Did you get this fixed at all? I'm having a similar issue now when trying to rotate around the Z and move up/down in the Y.

–