Rigidbody physics problem. Why does the objects coordinate plane not rotate?

My objects coordinate system doesn’t seem to rotate correctly when it collides and turns when hitting other objects. For example, it will move, but it will move as if it were facing the original direction before the collision. I have tried adding torque through script and it seems to act fine via that method.
#pragma strict

function Start () {
	rigidbody.AddTorque(Vector3(0, 250, 0));
}
var w : boolean = false;
var s : boolean = false;


function Update () {
	if(Input.GetKeyDown(KeyCode.W))
	{
		w = true;
		
	}
	if(Input.GetKeyUp(KeyCode.W))
	{
		w= false;
	}
	if(Input.GetKeyDown(KeyCode.S))
	{
		s = true;
		
	}
	if(Input.GetKeyUp(KeyCode.S))
	{
		s = false;
	}
	
	
	if(w && rigidbody.velocity.z < 10)
	{
		rigidbody.AddForce(Vector3(0, 0, 250));
	}
	if(s && rigidbody.velocity.z > -10)
	{
		rigidbody.AddForce(0, 0, -250);
	}


	
	
}

1 Answer

1

Add force is in world coordinates, so your AddForce() will always be in the same direction. You have a couple of choices to fix the problem. You can use Rigidbody.AddRelativeForce(), or you can use the calculated vectors in the transform like Transform.forward.

I agree with robertbu in the Transform.forward that is how I move all my objects in my games

The AddRelativeForce() works well for my purpose. This is kind of a little side question. What makes an object not turn as easy when it hits an object? Should I turn angular drag up?