Ajil Pappachan
Ajil Pappachan

Reputation: 66

Move Unity navmesh multiple agents to single point and stop pushing each other

I am making a game that requires multiple characters to navigate through narrow pathways. I keep getting this problem where the characters keep pushing each other at junctions and get stuck. There is not enough space to maneuver and avoid each other.

I tried a workaround I found here but this causes an issue since navmesh obstacles can be carving or non-carving. If I go with non-carving, one character stops moving so that the other can pass through but often the other character keeps trying to push away the stopped bear and they both get stuck. This is resolved by making the obstacle carving, as the other character will recalculate a path around it. However, this means that when the stopped character starts moving again, it jerks a little since the place it was standing on doesn't have any navmesh data so the character snaps to a place that does.

Even when the characters do manage to get to their target location, another issue is that character one reaches the target point and other characters keep pushing on to the first character, trying to reach the target location, instead of coming to a halt, as showcased here.

I'm more than happy to provide more information if required and any help would be greatly appreciated. Thanks in advance.

Upvotes: 1

Views: 2598

Answers (1)

TEEBQNE
TEEBQNE

Reputation: 6276

An alternative solution would be to set the physics layers of the AI to not collide with itself. When doing this, the AI will not push and shove each other, but glide over one another. It will alleviate both issues you are having.

Go to Edit->Project Settings->Physics2D->LayerCollisionMatrix

Layer Collisions

Here you can disable the collision between the layer that your AI is on. I would recommend adding a new layer to the AI so it can not collide with just itself but act normally with all other colliders. To assure they do not collide, find the layer on both the row/column in this matrix and uncheck the box where the layer meets itself.

If this alternative solution will not work for you, I can recommend something else.

Upvotes: 1

Related Questions