- Home /
Question by
glasshalfpool · Feb 27 at 09:42 PM ·
rigidbodytorque
How do I make AddTorque take account of angular velocity
I am currently adding torque to rotate a rigidbody:
float torqueForce = 4.0f;
rb.AddTorque(transform.up * torqueForce * moveHorizontal, ForceMode.Force);
I need to adjust this so that the torque added takes account of the current rotation of the rigid body. For example if you steer left and then right, the torque added to turn you right is reduced by a factor dependent on the current amount of left rotation.
I think it would be possible to do this with a bunch of if statements, something like:
if ((rb.angularVelocity.y > 0.0) && (moveHorizontal < 0))
{
rb.AddTorque(transform.up * (torqueForce - rb.angularVelocity.y) * moveHorizontal, ForceMode.Force;
}
else if ((rb.angularVelocity.y < 0.0) && (moveHorizontal > 0))
{
rb.AddTorque(transform.up * (torqueForce - rb.angularVelocity.y) * moveHorizontal, ForceMode.Force;
}
else
{
rb.AddTorque(transform.up * torqueForce * moveHorizontal, ForceMode.Force);
}
This seems like a really cumbersome way to do it. Any suggestions?
Cheers, J.
Comment
Your answer
Follow this Question
Related Questions
Freeze Rotation constraints doesn't work. 2 Answers
Understanding how torque is applied 2 Answers
Apply torque to align rigidbody to a specific angle in 3D 2 Answers
Local Rigidbody.AddTorque? 1 Answer