- Home /
Why is rigidbody.AddRelativeTorque not working?
I am trying to write a script that will add rotation (torque) to the rigidbody of an object. I thought this would be easy, but it has proved to be quite problematic. This is what I have-
function Update () {
if(Input.GetKey("e")){
rigidbody.AddRelativeTorque (Vector3.up * 10);
}
}
What am I doing wrong? I'm not new to Javascript, and this script is VERY straight and linear. It IS applied to my object, and I am pressing E. Here is my inspector-
This is really annoying.
Thank you
You need to use FixedUpdate for physics functions, since this code will fail to work correctly when the framerate varies.
If the thing you are trying to spin is sitting on the ground, the friction of the ground will prevent it from spinning. Try adding a physics material to your object, or trying to spin it when it is not resting on the ground.
Answer by xt-xylophone · Feb 03, 2014 at 01:44 AM
Everything looks ok. Put the angular drag to Zero to make sure as well, that number might be too low.
Try using:
if(Input.GetKey(KeyCode.E)){
I've never done it your way and can't test either way until later tonight but Ive used my way A LOT and its 100% correct. If that ^ doesnt work there must be something else we don't know.
thanks, I will try that. I debugged the Get$$anonymous$$ey("e"), so I know that's not the problem
Try turning gravity off, it cant rotate while on the ground, too much friction. Also try it with your animator turned off.
Your answer
Follow this Question
Related Questions
Collision of Character collider not working? 1 Answer
Rigidbody.Addforce not working in Unity 5.4.1 3 Answers
Unity says that my script isn't doing anything? 1 Answer
For statement stops function? 1 Answer
For loop not working? 1 Answer