Possible to have agents navigate around water or go under/through it depending on the situation?

Hi there,
I am working on a top-down point and click game set on an island (made up of Unity terrain objects). When I give one of my charcters a move command I would like them to navigate around the water when walking around on the island, but at the same time walk through shallow water or swim through the water if told to do so. For example, if told to collect an item in the shallows or swim to an object floating in the water. Also, the water level changes as the tide goes in and out.

Would this pathfinding solution allow me to change when an agent can walk through the water or whether they should avoid it on the fly?

Thanks :slight_smile: ,
Felix.

Hi

Yes, that is possible.
I would recommend that you use tags: https://arongranberg.com/astar/docs/tags.php

You mark the water with a ‘water’ tag and leave the rest with the ‘basic ground’ tag.
Then on the Seeker you can set the penalties for different tags, i.e the cost of moving across a node with a particular tag. When you allow the character to move in the water you would set both penalties to 0. When you want to discourage them from walking in the water you would set the penalty for the water tag to something really high, like for example 100000. Using penalties instead of completely preventing them from walking on those nodes is usually better as they will more gracefully handle the case when they are in the water and you suddenly prevent them from being there, and also they will be able to walk through the water if there is no other way to the destination.

Hi Aron, sorry about the late reply.
Would this allow the Seeker to ignore collisions with the water and walk along the ground under it? For example, if walking in shallow water. I’ve played around with the second example scene (the one with the terrain, lake and moving obstacles) and couldn’t get the bot to walk under the lake. Is there a way to do that as well using your system or would I have to do something like offset the Seeker by the depth of the water to make it look like they are walking through it?

Thanks for your help!
Felix.

Never mind, I got it to work in my scene by setting the colider on my water object as a trigger.

Thanks again :slight_smile:
Felix.

1 Like