How can I animate a death sequence for the FPS controller?

Hi,

I am using the FPS prefab and I want to make an animation for when you die. Basically, just rotate it a bit until and eventually fall on the floor, and fade to black.

I have created an animation in unity which basically does all this. However, because I need to put a keyframe at the start of the animation, whenever it plays it resets my character to the original co-ordinates. So if I'm looking east when I make the animation, the character suddenly looks east before the animation plays.

Does that make sense?

Basically I need the animation to play from whatever position the player is in. How would I do this?

Hope someone can help! Cheers

The animations are in local-space which is world-space for your FPS controller since it doesn't have a parent. I would parent an empty gameObject to the FPS controller right before the player collapses with the same rotation and position as camera.

Then create your animation with the expectation that it is going to be in local space at the start of the animation. Start at 0 degrees rotation instead of some other number so that is stays looking forward in local space at the start and animate your FPS controller from there. And start at (0, 0, 0) for your position so that in local space it remains at the same spot when the death animation starts.

If you try and test your animation without a parent though, make note that the player will jump from there current position to the origin.

So after you make your animation your script may look something like this:

function Die () { //Another function calls this.

     var gO : GameObject = new GameObject();  //Create an empty gameObject.
     gO.transform.position = transform.position; //Set its position and rotation
     gO.transform.rotation = transform.rotation; //  to match the camera's so 
            //there won't be a jump from the position to the animation position.

     transform.parent = gO.transform;

     animation.Play("NameOfYourDeathAnimation");
}