- Home /
Change player's y-position for a specific animation
Hi everyone !
My player is a witch who has an "idle" animation and a "flying" animation. However, the "flying" animation is fixed on the ground, I would like to move the witch a little bit up in the air (y = 0.2) but only when the "flying" animation is performing.
Here, my witch is infinitly moving up.
void Animating (float h, float v)
{
bool flying = h != 0f || v != 0f;
if (flying)
{
animation.CrossFade("fly", 0.2f);
transform.Translate(0, 0.2f, 0, Space.World);
}
else
{
animation.CrossFade("idle", 0.2f);
}
}
I found a similar subject, but the suggested solution doesn't work for me : http://gamedev.stackexchange.com/questions/74335/how-to-change-transform-position-x-after-a-state-is-changed
How can I just have my witch in position (x, 0.2, z) only during this "flying" animation ?
Answer by Hokkohono · Feb 20, 2015 at 05:26 PM
Ok, find myself the solution on others pages of this website, sorry ^^
bool flying = h != 0f || v != 0f;
Vector3 temp = transform.position;
// Animate
if (flying)
{
temp.y = 0.5f;
transform.position = temp;
animation.CrossFade("fly", 0.2f);
}
else
{
temp.y = 0f;
transform.position = temp;
animation.CrossFade("idle", 0.2f);
}
// Move the player to it's current position plus the movement.
playerRigidbody.MovePosition (transform.position + movement);
Great, you've learned the importance of looking for answers before posting questions.
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
Animated object changes position when animation is played. 1 Answer
Player GameObject changes position when I start the game 4 Answers
Create Player From Values [ Photon ] 0 Answers
Switch between animations but keeping frame number? 0 Answers