- Home /
Box Ridigbody rotates faster left than right
Hey all,
I think I have a pretty straight forward problem.
I have a rigidbody attached to a box collider and I am moving it foward with:
m_rigidbody.AddForce((((inputAccel * SPEED) * transform.forward) * weight) * Time.deltaTime);
Weight is the actual weight of the rigidbody, SPEED is 2000, and the inputAccel is a float between -1 and 1.
That part seems to work fine, however; my issues come from rotating the rigidbody. Which I do with:
float angle = Mathf.Lerp(0, 180, Mathf.Abs(turn)) * turn;
Quaternion deltaRotation = Quaternion.Euler(new Vector3(
0, angle, 0
) * Time.deltaTime);
m_rigidbody.MoveRotation(m_rigidbody.rotation * deltaRotation);
I've tried using AddTorque and I got this code from https://docs.unity3d.com/ScriptReference/Rigidbody.MoveRotation.html
The rigidbody seems to turn sharper when moving along the ground right more so than left.
This issue has been driving me crazy and thank you in advance for the help!
Answer by Bunny83 · Aug 13, 2019 at 12:10 AM
Have you actually confirmed that your turn value reachest the same value in the positive as well as in the negative area? Keep in mind that you have a quadratic saturation, so a small change when close to 1 or -1 will have a much larger impact on the angle than when close to 0.
Also are you sure you don't have and additional forces? For example the rigidbody could have an angularVelocity in one direction and your manual rotation has to work against it in one direction and is added in the other. Also make sure you don't collide with anything while rotating. If your object sits on the ground and is pushed down by gravity, make sure it's actually aligned with the ground perfectly. If your rotation axis is slightly tilted you may rotate an edge into the ground.
Finally I'd like to note that AddForce with ForceMode.Force (the default) does not need deltaTime and has to be used inside FixedUpdate. That's something we can not verify from your code snippet. The force should be given in newtons. If you have trouble understanding the different force modes, see my answer over here
It's pretty apparent that it turns faster left than right. Not sure of a good way to measure it besides the forces being applied to it.
I have angularVelocity set to 0, but I changed that thinking it would do something. It didn't seem to have an effect?
I actually raycast to the ground and allign to its normal beneath the box to ensure that it's lined-up, I disabled that too to see if it was messing with the rotation. No Effect :(
I manipulate my rigidbody in FixedUpdate as well.
You know what it was...
It was the multiplying by the Time.deltaTime...
I went back to addTorque and it works perfectly
Thank you :)
Your answer
Follow this Question
Related Questions
Box collider (with Rigidbody attached) gets stuck into another Box Collider 0 Answers
Rotate Rigid body simple car controlls 1 Answer
OnTriggerExit happens too soon! 1 Answer
Why do I get OnTriggerExit upon collision when a rigidbody is kinematic? (example) 3 Answers
i wanna prevent my collider from falling down flat when climbing slope 0 Answers