Support Forum

A few beginner questions about direction/destination

I am using A* pathfinding to make a point and click game and have it working nearly flawlessly, but I have a few questions.

  1. How can I determine what direction the player should be facing so I can have the correct animation play at the correct time? I was thinking I’d have to compare original and new values of X/Y for diagonal movements, but I’m not entirely sure how I’d be able to pull this off. I experimented with watching the rotation of the object, so if the GameObject is 45 degrees then the player would be going diagonally to the left and -45 they would be going diagonally to the right. The same applies to 135/-135 and 90/-90, but the problem is when the player hits a collider these numbers aren’t locked. I would want to make sure that when the player runs into a collider it’s a dead stop no rotation altering.

  2. Is there a function I can call to stop the AI from continuing to the destination mid transition? When I go from one scene to another the character immediately tries to go to the X,Y coordinates from the previous scene. (My AI object is my player object because of the point and click nature of my game, so this object is not destroyed on a new scene).

Thanks in advance!

  1. Usually the best approach is to check the ai.velocity property and use that to choose the animation.
  2. You can call ai.SetPath(null) to clear the path it is currently following.