- Home /
AddRelativeTorque - spaceship not properly spinning around axis
Hello,
I've been trying to turn my spaceship with the AddRelativeTorque function from Rigidbody. Now this does seem to add some sort of forces to the game object, but not quite in the right direction.
void Awake()
{
rigid = GetComponent<Rigidbody>();
rigid.centerOfMass = gameObject.transform.localPosition;
}
void Update()
{
rigid.AddRelativeTorque(-transform.forward * gearRight * spaceship.turnSpeed * Time.FixedDeltaTime);
rigid.AddRelativeTorque(transform.forward * gearLeft * spaceship.turnSpeed * Time.FixedDeltaTime);
Debug.Log("transform.forward: " + transform.forward);
Debug.DrawRay(transform.position,transform.forward * 10f, Color.red);
if(gearLeft == 0 & gearRight == 0)
{
rigid.angularDrag = 3f;
}
else
{
rigid.angularDrag = 0f;
}
}
My problem is that the spaceship isn't spinning around its z-axis like it should, but all over the place. If I'm actually close to the world z-axis it's sort of close to what should happen, but if I align my ship with the x or y axis, it's just weirdly turning. I don't understand why that is. My debug Code clearly shows the correct axis, but the application of torque doesn't seem to care much about that. Anyone got an idea why that might be?
Your answer
Follow this Question
Related Questions
Rigidbody rotation around CenterOfMass 1 Answer
How to make 2d Vehicle/car physics in unity 3d 4.3 2d physics? 1 Answer
Calculate force for torque by specifying a required velocity 1 Answer
RelativeTorque and Vector3.Cross to look at an object 0 Answers
AddTorque not increasing relativeVelocity magnitude of a collision 1 Answer