0
\$\begingroup\$

How to use a Rigidbody on a game object after animation in Unity?

I want to play an animation fully controlling the positioning of the elements, i.e. ignoring physics. And after an animation plays till the end I want physics to resume affecting the element.

Right now to get the expected behavior I have to remove the Animator after an animation. I thought that maybe there is a neater way to do what I want, but I did not find it, so decided to ask here.

enter image description here

UPDATE

I just found a better way to achieve what I want. Instead of removing the Animator component I just disable it:

animator.enabled = false;

It feels better. But still I am hoping for a neater solution.

\$\endgroup\$
8
  • \$\begingroup\$ Have you tried isKinematic ? docs.unity3d.com/Manual/class-Rigidbody.html (I am still on my first or second readthrough of the manual and haven't tested it myself yet). \$\endgroup\$ – Emil Mar 25 at 6:55
  • \$\begingroup\$ @Emil, it seems your comment has nothing to do with my question. Otherwise, could you elaborate it, please? \$\endgroup\$ – some1 here Mar 25 at 19:52
  • \$\begingroup\$ @some1here Is Kinematic If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform. This is useful for moving platforms or if you want to animate a Rigidbody that has a HingeJoint attached. \$\endgroup\$ – Zibelas Mar 25 at 20:05
  • \$\begingroup\$ Your "Update" should be posted as an Answer - it's worth an upvote on its own. Don't worry, even an answered question can still get other answers, so you won't be blocking alternative solutions. (Though myself, I'd say this is exactly the situation animator.enabled = false exists to serve) \$\endgroup\$ – DMGregory Mar 25 at 20:09
  • \$\begingroup\$ @DMGregory, yeah. You are reading my mind. I wanted to get an answer, so I did not post the update as one :) \$\endgroup\$ – some1 here Mar 25 at 20:11
0
\$\begingroup\$

To make physics affect rigidbody after playing an animation we can disable an animator.

One way to do that is through the animation event which would call a script, which would disable the Animator:

//get an animator instance in any way
//e.g. through a property or through the .GetComponent<Animator>()
animator.enabled = false;

Another way is to disable an animator from animation itself. The Animator enablement checkbox seems to be an animatable property. But so far I was not able to do that.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.