Smart pathfinding

Hi Everyone.

I have a question in case anyone familiar with it. I cannot find a way to build smart pathfinding in order for units (character or pawn) to go around obstacles such as another unit or other non-static object.


In a screenshot, I have a unit that is unable to reach a point because trying to go through other units. How I can code it in order to go around other units?

Best regards,
Alexander

Hi,
You don’t need to code this.
To avoid obstacles in some radius you need to adjust RayCastNavMesh

To make the same radius around actors you need to turn on dynamic nav mesh in the settings (Project Settings → Navigation Mesh → Runtime Generation)


After that, you need to create a custom nav area

Open it and adjust the pathfinding cost (put some big numbers)
1677058541881
And the last thing, you need to attach a Sphere Collision component to your actor(don’t forget to scale up it, collision must be much bigger than actor itself), turn off all collisions, and set navigation settings like that (don’t forget to set your custom nav area)

The idea is pretty simple, each actor will have an area with high cost around, and this area will be avoided by other actors

More information about pathfinding cost

1 Like

Thank you for the great answer, it works great in some situations, however, specifically to my question I probably need another solution.

Let me explain. Let’s pretend that the unit (as in the screenshot) is locked on the North, West, and East sides. It needs to go North. For that, you need to get out of the “room” on the South, get around it, and go North in the desired direction. But, the unit still trying to go forward and never go backward to get out of the situation.

This situation happens a lot when you have units attacking other units and need to get around in order to find a better spot for shooting. Instead, I have units shooting their teammates or just standing and waiting for the view to be clear to start shooting.

Everything that I described earlier might solve this situation as you expected.
Let’s assume that orange squares are 3 units around their blue target and the 4th is going to reach the target

As you shown it is working for Blue square, but it doesn’t for the Green one.

Also, this approach creates another issue that the unit unable to come close to the building and there fore, no longer able to interact (overlap) with buildings =))

The first approach is about keeping some distance from obstacles, in my case (I have huge spaceships) I need this to prevent collisions with static objects. In your case, you can keep this distance short.

The second approach is used to prevent collisions between AI and player

You can try EQS, it is a much more powerful tool but it might hit the performance

Thanks, I will try different approaches with this task.

This might help you