Ignoring Specific Agents in Local Avoidance (FollowerEntity)

  • A* version: 5.3.3
  • Unity version: 6000.0.41f1

Hi! I’m using the FollowerEntity with local avoidance turned on in a game where agents are auto-battling each other (melee attacks where attackers need to get right up next to their targets), choosing specific agents to attack and avoiding collisions with all others. In certain cases, an attacking agent will approach their target agent and end up swerving a fair amount before coming to a stop, even when no other agents are nearby.

When I put the attacker agent and the target agent on different RVOLayers and have the attacker ignore the target’s layer, it works as I would want it to with the attacker moving directly to the target and stopping. Unfortunately, I don’t want to opt targeted units out of any local avoidance other than that of their attacker (and only then so the attacker can get a smooth approach) and with only 32 layers it doesn’t look like this works as a solution for a game with lots of units.

I’ve also tried placing the destination point just in front of the actual target agent (relative to the attacker) when there’s a clear line of sight between the two but the local avoidance is still having the same effect. And that’s even when the target agent is stopped.

Any ideas would be greatly appreciated! Thanks in advance!

I had similar problems, but we’ve got less moving NPCs so juggling layers was more viable for me.

  • As the attacker gets close, I’d give them a higher priority so they’ll avoid less and others will avoid them more. Helps avoid them swerving if there’s more than the target NPC in the area, especially if another NPC is in their way.
  • When even closer, I move the attacker to another layer & let them ignore the default layer. They won’t avoid anyone else, but if they’re so close to their target they’re probably not moving around much, or they’re following the target that IS avoiding others. And they still have a higher priority so the others should still avoid them.
  • This leaves two attackers that won’t avoid each other. That hasn’t come up yet, because I’d have to set up a situation pretty carefully before they’ll cross paths while close enough to their target that their avoidance is disabled. (And kind of necessary for them to not avoid each other, in case they’re attacking someone who’s also attacking back.)

… but yeah, it’d be really nice to be able to turn off avoidance for specific agents.
Or to be able to set an agent as the destination, and have it auto-avoid other agents except for the one it’s following/targeting.

1 Like

Hi Tony,

Thanks for the thoughtful reply!

  • I think that adjusting priorities has worked a bit but I’m still seeing a sizeable swerve. In particular, reducing the priority of the target to 0. The Priority setting says “how strongly other agents will avoid this agent” so it made me focus on keeping the target’s priority low rather than setting the attacker’s priority high–because I want the target to be avoided less strongly by the attacker. But I will play around with the attacker’s priority as well to make sure I’m not missing something.

  • Moving the attacker to a different layer and having the attacker ignore the target’s layer actually does solve the immediate problem but causes a theoretical problem that seems hard to ignore: with only 32 layers and hundreds of units there’s no way around having attackers avoiding layers that have non-target agents on them. I don’t want attackers moving through agents they should be avoiding on their way to their targets. I haven’t seen this in practice because I haven’t set up a battle big enough but I’m sure enough that it’s going to happen that I want to find another solution.

  • I take your point that most of the time the layer solution will work. This will be my fallback if I can’t figure anything else out.

One solution I’m toying with that I might as well share is to reduce the Agent Time Horizon of the attacker as it approaches the target (so that arrival at the target is outside the time window). This seems to really dampen the attacker’s local avoidance in the immediate vicinity of the target but otherwise things seem to work normally like other agents avoiding the attacker and the attacker not intersecting with other agents. This doesn’t entirely eliminate the swerving but it’s better. I’m still testing.

Anyway, thanks for sharing. Good to hear from someone who is working through the same challenges I am!

1 Like

Yeah, for point 2 my situation is simpler than yours, so I just have the default layer for all the NPCs, and the attacker layer that I move the attacker to when they get close.

I don’t bother putting attackers or defenders on different layers per NPC, just those two “default” and “attackers” layer, so the complexity doesn’t explode. But it’s much less granular.

With the priority juggling I did still get some swerve. Setting priority fully to 0 or 1 created other issues.
I think I might have gotten around that by taking control of the NPC more strictly. Using the pathfinder calculations as input, but ignoring it and using my own values when I wanted.

I’m a little vague on the details because most of my work is around making the NPCs look right (procedural motion, IK body twisting etc.) so I know what code I’ve written but I don’t remember what the exact process I’m currently using is.
I use a lot of conditional code, weighting based on distance etc.

The time horizon sounds like an excellent solution!
I’ll try experimenting with that, too! Thanks! :slight_smile:

1 Like

An update: after some testing, it turns out that my strategy doesn’t work that well. Adjusting the Agent Time Horizon of the attacker based on distance from the target tends to cause problems when there’s crowding around the target. Units that are close to their target and have their time horizon reduced to near 0 don’t seem to find their way out of the crowd and to the opposite side of the target as well (ideally, I want attackers to surround the target).

To keep this from happening I’ve added a line-of-sight raycast from the attacker to the target and only reduce the time horizon when there is a line of sight. This seems to work but adds frequent raycasts for every attacker which isn’t ideal.

Depending on your individual games, could stopDistance be useful here? Have them stop a tad sooner to their target so they don’t swerve from the other agent’s RVO, because they don’t get close enough?