- Home /
AddTorque has no effect
Hi all, I am in the process of re-enginnering my project from transform based movement to addforce/torque based movement.
So far the addForce is working fine but i cannot get my object to rotate at all using AddTorque.
Here is the code I am using to move the object:
function FixedUpdate() {
horMovement = Input.GetAxis("Horizontal");
verMovement = Input.GetAxis("Vertical");
if (verMovement) {
rigidbody.AddTorque(transform.right * verMovement * verAcceleration);
}
if (horMovement) {
rigidbody.AddForce(Vector3(0, horMovement, 0).right * horAcceleration);
}
}
verMovement and horMovement are both set to 5.0. Can anyone tell me why it wont rotate? Thanks
Edited the answer I posted. Posting this comment as an auto-bump
Answer by OoglyWoogly · Apr 13, 2011 at 12:48 PM
Oh.... my.... god. I just found out the problem... and your gonna laugh.
I went into project settings physics manager, and set max angular velocity from 0 to 500 and it instantly worked. May have been a bit fast with a rotation speed of 1000000.0 but this can be easily changed. Im such a noob sometimes.
Thanks for all the assist.
I actually had the same problem, but because it was in Unity 5 the solution is slightly different. The max angular velocity is set on each RigidBody and, as far as I can see, needs to be set from code.
In unity 2019.3 its Project Settings -> Physics -> Default $$anonymous$$ax Angular Speed (near the bottom)
Answer by Proclyon · Apr 13, 2011 at 11:14 AM
Are you sure you are overwhelming the inertia of the object in your virtual environment ?
EDIT 4/13/2011 13:31 GMT+1
I believe another question on the site has the code and the discussion you need. This isn't a real double but it's good enough I believe, but you will have to judge that for yourself.
http://answers.unity3d.com/questions/51353/force-and-rotation
Hope it works out!
I think so. I just put verAcceleration up to 100000.0 and nothing happened so I think it is a problem with my code rather than the variables.I also just discovered that I had my X and Y axes constrained for rotation in the rigidbody inspector panel, so i unticked these but still nothing
Had a look at that edit you sent me and it still doesn't work. This is really odd.
Consider building a $$anonymous$$iature testcase. I always run two projects. The real deal and a simulation area in which I tweak one variable at a $$anonymous$$m and observe the changes. This takes a lot of work but it never let me down. That is the only other advice I can give you right now. I do hope that it is as usefull for you as it has been for me.
I am using a test scenarion at the moment unfortunately. Just tried to put it into another blank scene to make sure there werent any weird variables affecting it but still no rotation from AddTorque. Is there a setting that can prevent torque from being added?
Answer by Dr_D · Apr 20, 2016 at 03:34 AM
Maybe it's just me... but this seems to only work in FixedUpdate(). At least that's what I've found. Maybe it's a bug? I looked through the docs... not super thoroughly, but it doesn't seem to be stated anywhere.