I’ve got a little test bed running where by I hit an enemy and he dies (falls over Animation). Now I want the player to be able to walk over the body and collect him.
The issue I have is that if I hit this enemy again the death animation plays again.
To get round this should I Destroy the GameObject on the ground once the animation has finished, and then replace with a dummy model (pickup)? Or can I just stop the animation playing again somehow; even though the GameObject will be hit again and wants to replay the anim?
See what I’m doing at the moment is having the enemy as a Trigger, so I fire off the trigger to play the death animation.
I think potentially I might/should have to use OnCollision eventually instead?
To sum up, what would be the best way to allow me to:
Have an enemy (with collision in the game world) that is killed when struck
Killing [hitting] the enemy plays his death animation
Walking over the corpse allows the player to “pick up” the enemy
Hitting the prone/dead enemy again does not play the animation
I’m sure it’s simple, I’m just an utter newb to this!
I don’t have the scripts on me because I’m at work, but what you can do is wait for the animation to stop playing and then instantiate a ragdoll in the same position as the dead enemy on the floor. Then you can pick it up and it will look limp and when you strike it nothing will happen.
The instantiate ragdoll script is on the forum somewhere, just give a search.
Then do something like.
check to see if t he dying animation is playing.
if it is wait till it stops.
when it stops run instantiate ragdoll function.
the new ragdoll will contain the scripts to control moving it around.
Update; using the Clampforever really isn’t viable because one you try it on a lot of enemies the framerate drops to crap as it’s still playing animations!
I’m going to switch to the other solution, it’s more elegant anyway I feel.
However good to know the Clampforever and it’s been useful to help me get used to the animation usages
[I also found that you can change the animation mode itself in the inspector and select if you want it to animate once/clamp/ping pong, which is useful to know too].