Hi!
I am having trouble with detecting Direction.
It works just fine when I walk Up-left / Left-up or Right-down /Down-right
But for Top-right/Right-top and Left-down / Down-left I have a problem -
It detects wrong direction and for example my character animation is “standing -right” but if I want to shoot I shoot in UP-Direction because Direction is (0,1)
here is the code, I think that there need to be a very small fix which unfortunetly I cant figure out.
Thanks for help in advance!
float absX = Mathf.Abs(speedX);
float absY = Mathf.Abs(speedY);
if ((speedX <= 0 )&&(speedY>speedX)) {
// Debug.Log("4");
Direction=new Vector2(-1,0);
}
if ((speedY >= 0)&&(speedY>speedX) && (absX<absY)) {
Direction=new Vector2(0,1);
// Debug.Log("1");
}
if ((speedX >= 0 )&&(speedY<speedX)) {
Direction=new Vector2(1,0);
// Debug.Log("2");
}
if ((speedY <= 0)&&(speedY<speedX) && (absX<=absY) ) {
// Debug.Log("3");
Direction=new Vector2(0,-1);
}