# How would i track rotational direction from my rotation cordinates?

So I am trying to figure out the best way to track whether my camera is moving left, right, left diagonal down, left diagonal up, right diagonal down, right diagonal up, up, and down so I can animate my sword to the correct attack the direction asks for. Currently my code looks like this -

``````if(checkXPos > currentPos.x + moveBoundry && checkYPos > currentPos.y + moveBoundry)
{
//Left Diagonal Downwards
}
else if(checkXPos > currentPos.x + moveBoundry && checkYPos < currentPos.y - moveBoundry)
{
//Left Diagonal Upwards
}
else if(checkXPos < currentPos.x - moveBoundry && checkYPos > currentPos.y + moveBoundry)
{
//Right Diagonal Downwards
}
else if(checkXPos < currentPos.x - moveBoundry && checkYPos < currentPos.y - moveBoundry)
{
//Right Diagonal Upwards
}
else if(checkXPos > currentPos.x && (checkYPos > currentPos.y + moveBoundry || checkYPos < currentPos.y - moveBoundry))
{
slashLeft = true;
}
else if(checkXPos < currentPos.x && (checkYPos > currentPos.y + moveBoundry || checkYPos < currentPos.y - moveBoundry))
{
slashRight = true;
}
else if(checkYPos > currentPos.y && (checkXPos > currentPos.x + moveBoundry || checkXPos < currentPos.x - moveBoundry))
{
//Down Slash
}
else if(checkYPos < currentPos.y && (checkXPos > currentPos.x + moveBoundry || checkXPos < currentPos.x - moveBoundry))
{
//Up Slash
}
else
{
CancelAnim();
}
``````

So it already tracks my movement distance and my coordinate point that I’m looking at from one point to the another to make a line and I have check points to tell whether I am moving left or right, up or down from the difference of the two updating coordinates. How should I go at this and if there is a better method please by all means let me know thank you.

No a better method, but you can clean up your code a bit, it’s too confusing! You can nest your conditions to remove some duplication. For example:

``````bool movingLeft = checkXPos > currentPos.x + moveBoundry;
bool movingDown = checkYPos > currentPos.y + moveBoundry;
bool movingUp = checkYPos < currentPos.y - moveBoundry;
bool movingRight = checkXPos < currentPos.x - moveBoundry;

if(movingLeft){
if (movingDown) {
//Left Diagonal Downwards
} else if (movingUp) {
//Left Diagonal Upwards
} else {
//Left
}
} else if (movingRight) {
if (movingDown) {
//Right Diagonal Downwards
} else if (movingUp) {
//Right Diagonal Upwards
} else {
//Right
}
} else if (movingDown){
//Down
} else if (movingUp){
//Up
}
``````