When i play my “turn left” animation twice, the player snaps back to the start position at the start of the second animation.
The “turn left” animation rotates the player 90 degrees. I would expect that playing the “turn left” animation twice would cause the player to face the 180 degrees from the start point (facing opposite direction).
Why does the player snap back to the start position on the second play of the animation ? How can i fix this issue ? Is it possible to animation rotations to control the movement of the player or is Unity severely limited and i should look at a better 3d game engine, that is more capable ?
Playing an animation twice will, simply, play it twice. Just the same, when you watch a movie of a character running across a screen, if you go back and watch it again, the character will always be at the same place at the same frame. An animation is just like a movie.
Why not alter the character’s transform by using Transform.Rotate ?
This would allow you to create a speed variable and then you can alter how quickly the character turns, etc. I would recommend multiplying this speed variable by Time.deltaTime to make sure your transformation is independent of frame rate.
The issues is that the player is a “aircraft” and the turn left is not a simple rotate 90 degrees. The animation is a series of turns to turn the player 90 degrees.
A solution i have developed that almost works is below. The script takes the animations from the child after the animation has completed and then puts those rotations in the parent and zeros the rotations of the child. This works because the next time the animation is called the child (that is animated) starts at absolute value of 0.
The problem is that that the player appears to do a jumo to a position. I am not sure if that is because two adjustments to rotations parent, child causes flicker. Does anyone know a better solution ?
if (!animation.isPlaying && wasPlaying)
//only swap transfroms if rotaions have changed
if(animatedChildGameObject.transform.rotation != Quaternion.identity)
Quaternion qVals = new Quaternion(Utility.GetAircraftRoot().transform.rotation.x,
animatedChildGameObject.transform.rotation = Quaternion.identity;
parentGameObject.transform.rotation = qVals;
wasPlaying = animation.isPlaying;