Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Chasing a target using pathfinding

Discussion in 'Scripting' started by siflandolly, May 2, 2012.

  1. siflandolly


    May 17, 2011
    What is the recommended way to have an AI chase a target like the player using pathfinding? I am using A* for pathfinding. If the AI is chasing someone who is moving I don't want to keep recalculating a new path each time the target moves. Is there a typical design pattern people follow for this problem?

    I was thinking of trying to have the AI move directly toward the target first without pathfinding, then if it hits something use pathfinding. Or maybe use raycasting to see if something is in between the AI and the target and use pathfinding only if there's something in the way.

    Anyone have any recommendations?
  2. bigmisterb


    Nov 6, 2010
    I would recalculate the path every 1 second or so. This will cut down on the amount of stuff you are trying to do.

    You could do a simple raycast to see if the person is visible every frame. If so, use it to limit the impact of the AI.