Using A* Pathfinding with Dynamic Water Physics 2 for Ship Navigation

Hi,

I’m trying to integrate A Pathfinding Project* with Dynamic Water Physics 2 (DWP2) in Unity.
My goal is to have ships navigate on the sea using pathfinding while still being affected by buoyancy and waves from the water system.

The problem I’m running into is that both A* components and DWP2 components try to modify the ship’s Transform, which leads to conflicting behavior and not the result I expect.

Additionally, since water surfaces (like KWS water) are not scan-able for graphs, I currently place a hidden plane underneath the water and use that as the navigable surface for agents. This technically works, but it feels like a hack.

Questions:

  1. What is the recommended approach for combining pathfinding with physics-based buoyancy systems?

  2. Is there a known/better way to handle pathfinding on water without relying on an invisible plane beneath the water?

Thanks in advance for any advice or examples!

If it were me, I feel like I would probably do something even more hacky. :slight_smile: Like, have a separate invisible agent that walks on the invisible navmesh, and have the boat follow that agent’s x/y coordinates while letting the physics bob it up and down in the z direction (or however your coordinates are set up).

2 Likes

Definitely doesn’t feel like a hack to me- feels like a solution to a problem :smiley: Which kinda answers your second question. Short of generating a new graph every second or so to match the waves, I think this works fine.

For your first question I think this is where you’d want to start crafting a custom movement solution using Astar as a base. Basically let Astar calculate the “where” and your custom movement calculate the “how” with respect to your water physics.

Some related reading:

1 Like

Thanks for the suggestion!
I actually tried something similar in the beginning with a “pilot/ghost agent” approach. The problem I ran into was that since the pilot and the ship were under the same hierarchy, the pilot would move on its own but then the ship following it would effectively double the movement, which caused strange results.

If I understand you correctly, you mean the pilot should be a completely independent object, right? In that case, does it mean I’d need to spawn one extra invisible pilot object for every ship in the scene? I was wondering if that’s the normal/expected approach, or if I might be overcomplicating it.

Thanks a lot for clarifying!
Yes, this is very close to the conclusion I came to as well — let A* handle the “where” while I push the ship forward using DWP2’s inputs for the “how.” It basically works, it just needs some polish.

At the beginning I was wondering if there might be a simpler/easier method, because this approach felt a bit like overengineering to me. But it’s reassuring to hear you also see this as the right solution. Thanks also for the links, they’ll be really useful.

If I understand you correctly, you mean the pilot should be a completely independent object, right? In that case, does it mean I’d need to spawn one extra invisible pilot object for every ship in the scene?

That’s what I was suggesting, yes. And then you’d have a simple script that just causes the ship to follow the agent. There are a few different ways to do this, for example lerping between the two positions.

Is it normal? Not really. But it’s relatively easy to do, and might get you most of the way to what you want.

1 Like