Scripting – Hexagonal Character Movement
•
Example 3: Character movement in a hexagonal tilemap (+ pathfinding)
private void UpdateAnimation(){
int direction = 0;
if (currentPath != null){
float angle = Vector3.Angle(currentDestination – transform.position,
transform.right);
if (angle < 10)
direction = 4; //right
else if ((angle > 170) && (angle < 190))
direction = 1; //left
else if ((angle > 10) && (angle < 90) && (transform.position.y <
currentDestination.y))
direction = 3; //top right
else if ((angle > 90) && (angle < 170) && (transform.position.y <
currentDestination.y))
direction = 2; //top left
else if ((angle > 90) && (angle < 170) && (transform.position.y >
currentDestination.y))
direction = 6; //bottom left
else if ((angle < 90) && (transform.position.y > currentDestination.y))
direction = 5; //bottom right
}
animator.SetInteger("Direction", direction);
}