- Home /
Rotation after death animation problem.
I've made a system that where my players y position is initialized in the start function, and calculated that if the players y position(Falling) is greater than 8, and when the player hits the ground, then kill the player and play the "Death" animation, which is just a basic animation that rotates the players on it's Z axis. The problem is after it plays the death animation and the player spawns back at the spawn point, the player is still rotated on it's Z axis, exactly as the Death animation left it.
I have tried rotating the player back to normal the same way I made the spawn function and have looked around for answers, but nothing will work.
Here is the Death and spawn function
public void playDeathAnimation(){
if(isDead){
animation.Play("Dead");
}
}
public void spawn(){
isDead = false;
respawnTimer = 0;
health = 100;
transform.position = spawnPoint.position;
}
}
Sorry if I haven't been very specific, it sounds like a bit of a mouthful.
Answer by alexfeature · Dec 28, 2012 at 01:06 PM
Your player object is never actually recreated. You simply reset its internal variables. So the rotation of the object is same as what it was after the animation finished.
You should also consider rotating the object back to normal after you move it back to the spawn point.
For example
transform.rotation = spawnPoint.rotation;
This will rotate the player in the same way as your spawn point.
Hope this helps, Alex
$$anonymous$$ has a point here you are just resetting the position of player and that doesn't mean that your player rotation is reset.....so you first hold the value of starting rotation into a variable and at the time of respawn fetch the values from there or you can follow the line alex has pointed.......Cheers....Enjoy
Sorry, I wasn't very specific. I did try doing exactly that, infact it was the first thing I tried, but it didn't work
No, I'm going to try and add another spawn point inside the spawn point that is smaller, and see if I can change my players rotation to that ins$$anonymous$$d.
Change the rotation of the spawnpoint and see if that changes your rotation.
Answer by DarkSyntaxz · Jan 01, 2013 at 01:32 PM
Nothing worked, so what I did was to make another animation that flips the character back up when he spawns, and to make this invisible I will switch the players camera while he is spawning to something else and move the player to a 2nd spawnpoint where he flips up before he spawns, and changing the camera back to player view.
Thanks for your help anyway,
Brendan