Search Unity

How to extract Avoidance Steering from the NavMeshAgent Component

Discussion in 'Navigation' started by Eduard6421, Apr 9, 2019.

  1. Eduard6421

    Eduard6421

    Joined:
    Oct 13, 2013
    Posts:
    4
    Hello!
    I'm currently trying to create a mall simulator. I've implemented steering behaviours such as: arrive / follow / orient / look and run / wander for my agents and I've managed to combine them with unity's native path finding.
    I'm making use of dynamic weights to sum up multiple steering types that combine into a final steering output which i send to my agent. I furtherly move the agent as following:
    Code (CSharp):
    1. this.transform.position += velocity * Time.deltaTime;
    The issue that I'm currently facing is that I'm in need of local avoidance so that agents don't hit each other.
    As per unity's documentation of NavMeshAgent and it seems that
    desiredvelocity
    contains the possible contribution of avoidance.
    First of all, to get any output from NavMeshAgent it seems that i MUST give my agent a destination or a path to follow and if i do this the agent will start moving with both the speed of the navmeshagent and my personal character controller.
    The avoidance component only takes in account the velocities of the NavMeshAgents. As such I thought of the following
    1. I'll change my agents to only move by making use of NavMeshAgent. I will modify the NavMeshAgentComponent.velocity by making it equal to the speed offered by my steerings;
    2. Somehow extract only the avoidance from NavMeshAgent.desiredvelocity;
    3. Add a weighted value of the avoidance velocity into NavMeshAgentComponent.velocity;
    But i cannot seem to be able to extract only the avoidance velocity. If i give the agent a target or a path it automatically includes the velocity used to move the agent towards the target which i clearly do not want as it is already computed in my steerings.

    Is there any way to do this with the NavMeshAgent API?
    If not, can i decompile unity's AI library so that i can make NavMeshAgent.desiredvelocity only return the NavMeshAgent avoidance desired velocity?
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I'm afraid what you're trying here won't be possible, Unity's NavMesh API is one of the remaining black boxes old Unity design was favouring.
    I am honestly somewhat wondering why you're still using the NavMeshAgents if you're controlling movement yourself with all the influences. Maybe you should just use the Agent to initially get a path, and then turn it off and do all movement on your own using the next position on the path as another influence?
     
  3. Eduard6421

    Eduard6421

    Joined:
    Oct 13, 2013
    Posts:
    4
    Thank you for your answer!
    I did not implement local avoidance steering. I'm using the NavMeshAgents because they make use of RVO. The path returned by NavMeshAgent.CalculatePath does not take into account possible collisions with other agents. Yet NavAgent.SetPath(path) or NavAgent.setDestination(targetPosition) do indeed make use of RVO.

    Unity's native avoidance system would greatly benefit me.
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Unfortunately that's blackboxed, like I said before. You might just want to roll your own RVO system here and only use the NavMesh system for the bare pathfinding which you then follow with your own steering behaviours.
    People also recommend Aron Granberg's A* project, although considering the work you've put in so far it might be more interesting to just continue rolling your own.