I am trying to figure out how to calculate the amount of torque to add to a physics door to make it open perfectly.
I have a simple physics-based hinge door set up in my game:
I would like to give the PhysicsDoor script a function that uses RigidBody.AddTorque() with ForceMode.Impulse to rotate the door to exactly the max limit of the HingeJoint. My problem is that I want to only call RigidBody.AddTorque() once, not every FixedUpdate() or something.
I have been at this for a while and can’t find anything that works or any posts that answer this question.
What Have I Tried?
I have tried the following inside rb.AddTorque(Vector3.up * [equation below], ForceMode.Impulse);:
- (desiredYRotation - currentYRotation) * rb.mass;
- (desiredYRotation - currentYRotation) * rb.mass * rb.drag;
- (desiredYRotation - currentYRotation) * rb.mass * rb.drag * rb.angularVelocity;
- (desiredYRotation - currentYRotation) * rb.mass * (1 + rb.drag) * (1 + rb.angularVelocity);
These are very stupid things to try, but I tried them anyway.
I have been realizing through my tests that I probably need to account for those forces as they are applied over time, rather than just those easy numbers. This is because when the drag or angularDrag is low, the force is too great, but when either or both are high, the force is too small.
SUMMARY OF WHAT I AM TRYING TO ACCOMPLISH
I am trying to calculate the amount of torque that I need to apply ONCE as an impulse in order to rotate a hinge door a desired amount of degrees.
POSSIBLY USEFUL INFORMATION
I don’t know much about physics so if you do, pardon my ignorance.
I think that the end result will probably be some kind of equation that uses the mass, the opposing forces, and the time it will take to rotate (likely deduced using the opposing forces), to find the correct amount of torque to apply.
Something like this maybe:
torqueAmount = [amount to rotate] * rb.mass * (1 + rb.drag) * (1 + rb.angularDrag) * timeToRotate;
(using 1+ for the drags since I think that’s the right thing… idk)
Here is the line of code I am using to apply the torque:
rb.AddTorque(Vector3.up * torqueAmount, ForceMode.Impulse);
It could also use the HingeJoint’s massScale or whatever that does.
Thank You For Reading! If you can help me, thank you again!
P.S. if this didn't make sense, I can try to offer clarification, it may take a few days though...



