- Home /
Returning a rigidbody back to its original x and z rotations through physics forces.
This is a little tricky to explain so bear with me.
Imagine an upright boxing bag. These bags can be hit and will then rotate along their x and z axis, However they will naturally stand upright again after a few seconds. It doesnt matter which way they are rotated on their y axis. The bag will always come back to its starting rotation after a while.
I am trying to do something similar in code with a rigidbody, however I find myself unable to solve it. How can I constantly apply physics forces that will return my rigidbodies x and z rotations back to 0 while still allowing stronger forces to rotate it. E.g a punch or kick to the upright boxing bag.
Answer by xxmariofer · Jan 30, 2019 at 08:34 AM
hello, that effect happens because the center of the bag has a lot of drag and the other part has less so the heavier part will always tend to go down, i dont really know how to explain it but by creating 1 big box with a lot of drag and angular drag, and imagine 2 little objects with almost no drag and angular drag (both of the objects attached to the big one using hinge joint) you can create that effect.
Not exactly what I did but this comment sent me on the right track thank you.
To get it working I set up a root rigidbody constrained to the y position and constrained to only rotate on its y axis.
A hinge joint attached to that root object with its axis setup (1, 0, 1) allows it to rotate on the x and z axis like I wished.
Finally I ticked use spring and played with the values so basically the connected body can now be pushed around and have physics forces applied to it while constantly trying to spring back to place. (Also the root object has more drag and angular drag than the connected body as you suggested)
This ended up working EXACTLY how I wished with absolutely no code required. Thanks for your help :)
Answer by misher · Jan 30, 2019 at 08:33 AM
Attach them at the bottom to something, and apply the constant force upwards.
Thanks for your comment. I ended up attaching the bag to a root object with a hinge joint attached. Ins$$anonymous$$d of applying constant force upward I found a spring option on the hinge joint which always tried to pull the object back to its initial rotation (like a spring). This worked perfectly
Your answer
Follow this Question
Related Questions
Rigidbody rotation with PID controller and torque 0 Answers
Constant Force doesn't work 0 Answers
Freeze Rotation constraints doesn't work. 2 Answers
AddRelativeTorque not rotating 1 Answer
add force to rotation 1 Answer