0

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?

setix
  • 1
  • 2
  • 1
    **never use else-if**. you will never, ever, ever, get it to work. rewrite with "breakaway" code http://stackoverflow.com/a/35224838/294884 or http://stackoverflow.com/questions/25228676/avoiding-nested-blocks-with-asynchronous-code-in-objective-c/25228698#25228698 – Fattie Feb 20 '16 at 23:28
  • @JoeBlow, can you elaborate on that? – AustinWBryan Feb 20 '16 at 23:36
  • This code is completely unreadable.... – AustinWBryan Feb 20 '16 at 23:36
  • Hi Austin .. dude there is THOUSANDS OF WORDS about it on the two "internet links" (look for the "blue color") in my comment just there dude - heh! how much more could I write? – Fattie Feb 21 '16 at 01:01
  • Hi @joeblow could you explain how I would write the statement for both x and y axis for a diagonal? – setix Feb 21 '16 at 01:19
  • Nevermind, I was able to get it with the switch statement. thank you!! – setix Feb 21 '16 at 06:31

0 Answers0