Search Unity

Beginner optimization questions

Discussion in 'Navigation' started by MadboyJames, Dec 27, 2019.

  1. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
    I want to get some thoughts on how to optimize pathfinding for a top down 2D shooter. I've done some pathfinding before (basic research and followed Sebastian Lague's A* tutorial) and it seems the best optimization is to "find a path" as little as possible.

    The game has enemies (up to 100) chasing the player around a building with a couple of mostly empty rooms. I figure that I can do three things to reduce the pathfinding load.

    First, is to have every enemy raycast towards the player every frame. If the raycast hits the player, then just follow with Translate(speed*direction). If the ray in interrupted, then the enemy needs to pathfind.

    Second, if the enemy has a path, then check to see if the player has moved more than a meter away from the final node. if the player did, then repath.

    Third, when an enemy finds a path, it gives this path to all enemies in a 2 meter radius around it (I'm not sure how to make them all be spaced while moving. How do I stop them from acting like lemmings traveling in single file?)

    Any optimization suggestion or recommendation is appreciated.

    Note: I have not used Unity's Navmesh system before. It seems to be a powerful tool and I'd like to get to know it for this project. These three optimization suggestions are based on the assumption that the navemesh system uses node based pathfinding.
     
    Last edited: Dec 27, 2019