I sincerely apologize for my first post being a question and quite a newbie question at that. I’ve just started fiddling with the API recently, so it is all quite fresh. I’ve looked through the documentation thoroughly and searched the internet, to no avail. All I am trying to do is apply torque to a RigidDynamic on it’s local axis so that no matter what direction my actor is facing it will rotate correctly. I’ve tried various options, but they didn’t work as I expected, the only solution I can think of is to calculate forward/side/up vectors and multiply this against a translation vector but that doesn’t seem the right way to go about it. Older information on the internet points to a addLocalTorque function which isn’t available in my version, am I missing something simple here? (PhysX-3.3.1)
The PhysX api supports torques applied in the global frame with the function PxRigidBody::addTorque.
Imagine that the up-vector is (0,1,0) and you want to rotate your character around the up-vector. The following code applies a torque of magnitude torqueAmount around the up-vector:
const PxVec3 up(0,1,0);
const PxVec3 bodyUpVector = myBody.getGlobalPose().q.rotate(up);
const PxVec3 torque = bodyUpVector * torqueAmount;
The sign of torqueAmount obviously dictates the rotation direction, while the magnitude dictates the change in angular speed that arises from the applied torque.
I hope this helps answer your question.
Thanks mate. The answer was virtually staring me in the face all this time as one of the lectures actually covered it. It even had a comment “// apply a relative force” in the code, I just didn’t fully understand what it meant until you explained it so neatly. Cheers