Search Unity

moving NPCs without NavMeshAgent

Discussion in 'Navigation' started by earlGrey_, May 19, 2020.

  1. earlGrey_

    earlGrey_

    Joined:
    Jan 30, 2020
    Posts:
    6
    Hi. I have a character class which is I want to use as is without inheriting or something to make a Bot out of it. Instead I'm binding IInputController interface to a different implementation which is my BotAI. This way I'm able to control my bots in exact same way as human players does. But I have some issue with navigation. I'll tell you briefly how I do navigation for bots:
    - disable NavMeshObstacle (which is carve obstacle) on NPC that are trying to calculate path
    - wait for FixedUpdate for NavMeshObstacle.enable = false take affect
    - call NavMesh.SamplePosition to find closest point on Navmesh to desired point
    - calculate path to desired point
    - re-enable NavMeshObstacle..

    It works, but the problem is that same times bots pushing each other and when they do that, each of them is trying to find new path, because of they see an obstacle (Raycast). So I think they just disabling their obstacles simultaneously and they could push each other forever like that.. So, my question is am I doing it the right way, or I should do something else? I'm about to switch to NavMeshAgents, but I really don't want to, cuz then it'll probably be a bit difference between human players and bots in term of their moving physics.
     
  2. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    Hi,

    There is two part of pathfinding. 1st global - finding general path, 2nd local - static and dynamic obstacle avoidance.
    NavMesh implements global pathfinding. while agent implements local avoidance. So you need to implement any real-time obstacle avoidance for your bot. The simplest, is to turn right on collision till collision happens. Or look for sophisticated methods. Here 9 page article https://www.gamasutra.com/view/feature/131724/smart_move_intelligent_.php