- Home /
How do I play death animation properly on unity3d
I am have a problem the is the death animation is not playing properly. I get to play when the enemy ai is far away. When I kill the enemy up close it just vanish . I have some code here :
/ Deactivate the object if requested.
if (m_DeactivateOnDeath) {
Scheduler.Schedule(m_DeactivateOnDeathDelay, Deactivate);
GetComponent<Animation>().Play("die");
GetComponent<AudioSource>().Play();
}
}
You might want to look into $$anonymous$$ecanim and the Animator component.
In any case, I suspect it is because you're moving the same object that has the Animation component attached to it. When you play the Animation, it takes over the coordinates and moves the object back to 0,0,0.
If this is the case, all you have to do is make the AI character a child of another object, and move that parent, ins$$anonymous$$d of the character itself
Do you mean drag the child to an empty gameobject ? I have the project if you wanna look at it . Its not a big project.
http://www.mediafire.com/download/qr2u3j2uula5do8/Testing+Game1.zip
Yea, sorry, can't really download that file. But yes, basically something like this
L Root
L Your Character (Animation)
And use Root for movement and rotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084720im_/https://answers.unity.com/themes/thub/images/avi.jpg)