Need general idea on how to approach 2D water and movement

Hi!

I am looking for little bit of guidance on how I should approach this scenario:

Game is 2D sideview. Characters can run between rooms and climb ladders to get to different floors. This is pretty simple stuff, I did this with point graph and it works pretty well. Water is quite integral element of the game; some rooms can be (dynamically) flooded and surface level can vary in rooms at anytime during the game. Few questions:

  • What would be a good general way to approach this?

  • My initial thought was to use point graph for walking/climbing and grid graph to detect swim zone. I am not sure how this comes together though, so is idea of using separate graphs for these a valid one? Point graphs underwater level would be blocked, and grid graph would be used for swimming instead.

  • My current point graph AI is actually not following the path directly, it’s just checking which direction has the next node and running/climbing towards it. Is this a “appropriate” way of doing things? Characters are rigidbody controlled.

  • Any pointers and good practices are welcome!

I’d appreciate if anyone has any input on this! :smile:

So I played around a bit and my general solution would be to use custom grid graph. Basically a grid graph which builds walkability that fits a side view 2D game (walk on top of colliders, climb ladders etc.). I’m still a bit lost on how to approach water, I’m going to test an idea where points filled with water get penalty applied to them making them less favorable. Deeper the water, bigger the penalty so knee deep water won’t really affect anything while fully flooded room would be practically impassable.

Is it generally an usable idea to put water navigation information on same graph or should I use separate one which maps only for swimming navigation?

Edit: And is custom grid logic a good idea? It seems examples are outdated so there’s a bit of work in researching how creating custom grid scan works. Could do this with grid update objects instead for example?

I think your solution would work.
If you are just modifying penalties and walkability, using GraphUpdateObjects would probably work just as well, but it might be a cleaner solution to use a custom grid graph.

You might want to consider using tags for the different regions.
http://arongranberg.com/astar/docs/tags.php

1 Like