Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Making enemies with distinct movement patterns work with navmesh

Discussion in 'Navigation' started by Yukken, Nov 5, 2019.

  1. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    43
    So I have enemies that have different movement patterns. Ex: one of them faces player while pivoting with shield, another one might want to stay away from player etc. The point is that they don't directly target the player when moving. So I can't set navigation target to the player. Unless I set the points every frame. Is that a bad idea? I see that navmeshagent.velocity exists. If don't want to beeline for the player but know which direction I want to go, can I just set that for the desired effect and not worry about collisions with obstacles?

    Another problem is that they must respect collision and stay away from each other. Navmesh already does that. But I also need to make them stay away from the player if needed. Like an enemy might wan't to back off after attacking. increasing stopping distance does not seem to make agents back off if they are already near the target.

    Sometimes I want to tell the enemy to flank the player Or simply maintain an angle with the player. Navmesh will always use shortest path. Is there any alternative to setting the target behind the player and hoping for the best in this scenario?
     
    Last edited: Nov 5, 2019
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    381
    You'll have to figure out a way to calculate their effective destinations for these and apply those to the NavMeshAgent.
    This is unfortunately going to be tricky business that will require plenty of testing in a variety of scenarios.
    Likewise you'll need to manually have your characters back off after attacking and the like. The NavMesh system is really meant to be a basic movement tool without any driving logic behind it. The driving logic is your job here.

    It might be a good idea to not use the NavMeshAgent for orientation and only use it for positioning instead. That way you can have an agent move around the player (and do stuff like keeping distance or charging the player), and handle the facing in animation and controller logic.
     
  3. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    43
    I figured as much. But if I at least have the directions, can I set them in navmeshahent.velocity without worrying about collisions? I've looked at the docs but it doesn't say anything definite on the matter.
     
  4. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    381
    I don't know, you'll have to try that out and perhaps document it. Messing about with agents' velocities doesn't seem like a good idea to me since you don't really know how the NavmeshSystem will respond to changes in velocity it didn't provide itself.
    From the little experience I have I'd say don't rely too much on agents' local avoidance kicking in to save you, I've found it to be very ineffective as soon as there's more than 2 or 3 agents getting close to each other.
     
  5. Yukken

    Yukken

    Joined:
    Jul 12, 2015
    Posts:
    43
    Oh well, at least I will have an excuse to make use of the steering behavior algorithms I learned.