I am new to c# and am working on a top-down 2d adventure game. I have my player moving in 8 directions, and the animator working in the 4 main directions (N,E,S,W).
I am trying to set up the blend tree in the animator for the diagonal movements, but am having trouble setting this up.
Here is my script.
public void PlayerAnimation(float moveHorizontal, float moveVertical, Animator anim, Player_Manager _PMS){
// IF we are moving we set the animation IsMoving to true
if(moveHorizontal != 0 || moveVertical != 0){
anim.SetBool("IsMoving", true);
}else{
anim.SetBool("IsMoving", false);
}
// We are wanting to go in the positive X direction.
if(moveHorizontal > 0){
// IF we have invert X on we adjust a different animation.
if(_PMS.invertX){
anim.SetInteger("Direction", 2);
}else{
anim.SetInteger("Direction", 4);
}
// We are wanting to move in the negative X direction.
}else if(moveHorizontal < 0){
// IF we have invert X on we adjust a different animation.
if(_PMS.invertX){
anim.SetInteger("Direction", 4);
}else{
anim.SetInteger("Direction", 2);
}
// We are wanting to move in the negative Y direction.
}else if(moveVertical < 0){
// IF we have invert Y on we adjust a different animation.
if(_PMS.invertY){
anim.SetInteger("Direction", 1);
}else{
anim.SetInteger("Direction", 3);
}
}else if(moveVertical > 0){
// IF we have invert Y on we adjust a different animation.
if(_PMS.invertY){
anim.SetInteger("Direction", 3);
}else{
anim.SetInteger("Direction", 1);
}
}else if(moveHorizontal > 0 || moveVertical < 0){
if(_PMS.invertX || _PMS.invertY){
anim.SetInteger("Direction", 7);
}else{
anim.SetInteger("Direction", 5);
}
}
}
I am using the "and" operator to call both x and y axis for the SE movement (last statement), but it does not register when I set it up in the animator. Is there another way I am supposed to call the diagonal movements?