I finally decided to register on this board as I have become stuck when attempting to solve an issue. Usually I can search the documentation, java docs, or forum and find whatever I am looking for. Anyway, I am attempting to make an physicsRigidBody rotate to face a specific direction using applyTorque() and could use some help. I have attempted creating a Quaternion and using lookAt. If I just set the rotation this of course works fine. I have also used slerp and multiplied the new Quat by the old one, used to angles, and used that as a torque vector. Anyway, just a small sample but I have tried everything I can think of…
I came up with something which semi works using that example. It still always misses the target rotation and backtracks but oh well. How would you improve upon his?
Nevermind, some reason the browser is not letting me paste the entire method.
Well. I may be wrong, but I think your vision of torque is false. Torque is a rotational force. It does imply a rotation but not set it.
I mean :
Torque => Angular speed => Rotation
If you want to stop the rotation, you have to apply reversed torque.
Thus, if you run your method each update, you will constantly overshoot as you apply reversed torque only when you have gone past your target… building angular speed all the way in. This reversed torque first consume angular speed and then start going to your target again… just to go past again.
Maybe you should look into some king of anticipation like PID controllers ?
@Yang71 - Nah, I understand the concept just how to get the correct vector to apply in order to rotate towards the proper direction. Honestly, I was and still am very tempted to simply use slerp and just set the rotation on the physicsRigidBody but I have read that is bad on this forum. Anyone know why not to do that? It would make things much easier
In essence you just cross product the direction you want your object to face, and the direction it’s currently facing. This gives you the axis (vector) to rotate around. Then you need to develop something as @yang71 suggests to prevent overshooting, and as suggested apply a reverse torque based on the current torque and the angle between the current direction and destination direction. Its never gonna be perfect, so you may have to decrease the tolerance to where its “close enough” to the destination vector that it won’t make a significant difference.