How to set animations for a top down shooter? How to change the animations by the player rotation?
I'm trying to set animations to my character for a top-down view shooter but the problem is that i can't set the animations to work properly(e.g. if i press S and look left the run_right animation should execute) I've made a blend-tree for movement which has other 4 blend-trees, one for each direction the character is facing(e.g if i look to west the west blend-tree should be active). the character is looking at a ray which starts from the camera that follows the character and goes to the ground. the script for animations is:
void UpdateAnimation(Vector3 dir, Vector3 rotation)
{
if (dir.x == 0f && dir.z == 0f)
{
//Idle Animation
anim.SetBool("Movement", false);
}
else
{
anim.SetBool("Movement", true);
}
if (rotation.y >= -57 && rotation.y <= 57)//North
{
anim.SetFloat("North", 1f);
anim.SetFloat("Est", 0f);
anim.SetFloat("South", 0f);
anim.SetFloat("West", 0f);
anim.SetFloat("DirX", dir.x);
anim.SetFloat("DirZ", dir.z);
}
else if (rotation.y >= 57 && rotation.y <= 123)//Est
{
anim.SetFloat("North", 0f);
anim.SetFloat("Est", 1f);
anim.SetFloat("South", 0f);
anim.SetFloat("West", 0f);
anim.SetFloat("DirX", dir.x);
anim.SetFloat("DirZ", dir.z);
}
else if (rotation.y >= -123 && rotation.y <= 123)//South
{
anim.SetFloat("North", 0f);
anim.SetFloat("Est", 0f);
anim.SetFloat("South", 1f);
anim.SetFloat("West", 0f);
anim.SetFloat("DirX", dir.x);
anim.SetFloat("DirZ", dir.z);
}
else //West
{
anim.SetFloat("North", 0f);
anim.SetFloat("Est", 0f);
anim.SetFloat("South", 0f);
anim.SetFloat("West", 1f);
anim.SetFloat("DirX", dir.x);
anim.SetFloat("DirZ", dir.z);
}
}
the value for vector3 rotation is taken from
Quaternion rot = transform.rotation;
Vector3 rotation = rot.ToEulerAngles();
the problem is that the animator is stuck on the north position and it doesn't change. I've tried to comment the north if statement and it works the same but now is stuck on the south tree. How should i take the rotation from the character in order to work? Here is a screen-shot from the animator
Your answer
Follow this Question
Related Questions
Smooth rotation on animation 1 Answer
Sprite rotation clip & ending position 0 Answers
my animation isnt importing, and the mesh stays on the T pose 0 Answers
animation got stuck 0 Answers
Visible Rotation from controller 1 Answer