0
\$\begingroup\$

I'm trying to create a "tree felling" effect, where the tree trunk falls over after being cut down by the player. I've used one prefab which contains my tree stump and tree trunk as children.

In its default state, my tree trunk as a rigidbody with isKinematic=true. When the player cuts down the tree, I begin an animation on the trunk which "tips it over". On the last frame, it sets isKinematic=false - at this point it should "fall over" because physicals/gravity is in control and the center of mass is definitely over its base.

However, the animation seems to be preventing it, like it's still "controlling" the transform.

  • Adding a transition from the "fell" state to an "exit" state just resets the position/rotation.
  • Setting the animator to "animate physics" kind of works, but the tree just flies away, probably colliding with the stump or something.
  • Disabling the animator after the animation kind of works, but this also causes the tree to go flying with some crazy physics.
  • When left alone, OnCollisionEnter is called on the tree for colliding with my ground, yet the gameobject appears to still be stuck at 45 degrees and never touched the ground. It seems like the rigibody/collider is not where the mesh/transform is?

Animating the object and then turning off isKinematic should work, it's been recommended to me on reddit and is the accepted answer on this question, so I'm not sure what could be wrong.

Edit: I can ease the physics problems by telling the trunk to ignore it's own stump (Physics.IgnoreCollision(Trunk.transform, Stump.transform);), but the base of the tree still "jumps" away from the stump, rather than "continue tipping over". I'm not sure what else could be at play.

\$\endgroup\$
0
\$\begingroup\$

A sudden jump in the physics behaviour can often occur if the tree's collider is intersecting with anything else the moment you switch off isKinematic (forcing the physics engine to apply a large impulse to move it out of this overlap), or if the tree has some accumulated velocity or angular velocity stored up that wasn't able to manifest previously because it was kinematic.

Can you double-check for penetration in the area the frame before you switch over, and forcefully zero-out the velocity and angular velocity?

Adding more mass or damping can also help smooth out small bumps.

\$\endgroup\$
0
\$\begingroup\$

what i understand from you question is, you sometimes need to control you objects by physics and sometimes by animation and translation. an object only can be controlled by one of them.

an standard way that works for characters is to make a parent object with colliders and rigidbody and a a child with model and animator. so everytime you want to make your scripted scenes, you just turn of the behaviour and make parent Object rigidbody to kinematic and after that you can bring it back to simple behaviour.

\$\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.