- Home /
Predict rotation angle for torque applied?
I'm using AddTorque to rotate a RigidBody and I need to predict how many degrees it will rotate in one frame knowing the torque, the angular drag and the mass (which in my case is always 1).
I've searched around pretty much but wasn't able to find a solution that fits my need, mostly because I'm not great with physics and couldn't extrapolate the solution from other formulas. Any help is greatly appreciated!
Answer by Bunny83 · Jan 25, 2021 at 11:11 AM
This is pretty much that hardest problem you could face when it comes to rigidbody physics. Rotational momentum is quite complicated. Note that mass does't matter for rotation. The intertia tensor is the mass equivalent for rotations. However for rotations it's important how the mass is distributed. So it depends on the shape of the object. Unity calculates the intertia tensor from all collider volumes and the provided mass.
The 3x3 interia tensor in Unity is stored as a diagonal matrix (intertiaTensor) combined with a rotation (inertiaRotation). The diagonal matrix represents the inertia around each major axis. So the calculation of the angular acceleration based on a torque is already quite complex. On top of that Unity's way to apply drag is not based on realworld physics but is simply a percentage drop of the angular velocity.
The angle change per frame is the angular velocity of the object. The terminal angular velocity depends on several factors. First of all Unity has a relatively low max angular velocity setting to ensure that physics do not get out of control. This has to be considered as well or you have to increase this limit in the physics settings. Other than that the terminal velocity is the balance between the acceleration due to the applied constant torque and the opposing drag.
I haven't ever tried this for rotation but the helper methods over here should work the same for rotations, given the right values.
Note if the object you're rotating does not have a uniform intertia around all axis and you apply a torque around a non local axis, so the axis relative to the object does change, it's impossible to calculate a proper value as the angular acceleration is quite different depending on the applied axis.
When you're dealing with a 2d rigidbody it becomes much easier as there's only one intertia value and one axis to rotate around. In 3d it's a nightmare ^^. Note that Unity's 3d physics engine does not perserve angular momentum but angular velocity. This is a simplification but prevents certain real world phenomenon like the intermediate axis theorem which is responsible for the tumbling seen in this video at the end. So In Unity you never get such tumbling. Once you stop applying a torque the rotation axis does not change because Unity preserves the angular velocity instead of the angular momentum.
Over here I already tried to explain some of the implications. Here's a gamedev question about the same topic.
Currently I don't have Unity (or a programming environment in general) at hand so I can't do any tests or provide any concrete code examples.
Thanks a lot for the extensive reply! I kinda expected this to be much harder than I thought due to the lack of precise resources around. I'm going to check and read all the resources you pointed out, and it looks like with your helper functions I should be able to sort this out. $$anonymous$$y setup is actually very easy, I'm just trying to AddTorque to a BoxCollider along its Transform.up and predict how much it will rotate each frame, using fixed AngularDrag and $$anonymous$$ass. I will report back with the results as soon as I get to work on this. :)
Well, this was quick: by using the helper method GetFinalVelocityFromAcceleration
you linked above, I was able to exactly predict the rotation degrees. I checked by printing both the prediction and the resulting angularVelocity
, and they matched perfectly. Thanks so much!
Wow that is a really in depth explanation there really well said and i would like to add something in to this https://www.youtube.com/watch?v=s-Ho5hF2Yww&t=457s as taught by Jonathon Weinburgurer of GameDevHQ.
Uhm, maybe I'm missing something but how is that related to calculating the angular velocity based on the applied torque and drag?.. o.O
but how is that related to calculating the angular velocity based on the applied torque and drag?
in dealing with the physics as such altering the for instance at 7:43 in the tutorial it shows augmenting the directions and in turn changes the angle and force out on it which when calculating the torque... let me ask you this what is the torque defined as being?
would it not be the centripetal force and applied gravity compiled in the center of mass due to velocity and the other aspects together?
Your answer
Follow this Question
Related Questions
Is there any way to keep increasing an object's angular velocity? 1 Answer
Rigidbody rotation with PID controller and torque 0 Answers
Add torque is not behaving same in opposite Y direction. Need help! 1 Answer
Compute the torque needed to rotate an object at a constant rate 3 Answers
Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers