5
\$\begingroup\$

I'm a little bit stuck on how I might go about programming dynamic, interesting water in a game. To qualify that a little bit, I'm interested in creating water with broad, rolling waves that affect collision, physics, and the visual shape of the mesh. As an example, here's a screenshot from Wave Race 64, a 1996 jetski racing game for the Nintendo 64!

Beautiful, no?

In Wave Race, not only do the waves move visually, but the choppy water pushes your vehicle around and creates bumps that give the game a really fun and unique feeling. I imagine that this type of thing is pretty standard in water simulation and physics, but I think the 'arcadiness' of the water physics in Wave Race makes it a pretty decent example.

I'm not really sure what steps need to be taken to create this effect though. I imagine that the visual effect of waves would be pretty simple to do create using a vertex shader, but I'm uncertain on how to program the physical 'entity' of the water. Here are some of my exact sticking points:

  • What might the data structure of that water look like?

  • And how does one 'animate' the physics/collision while keeping the visual mesh deformation in sync?

I have some "starting point" ideas, like possibly using a 2D or 3D vector field for the water. But I'm still fuzzy on the general implementation of fluid simulations, especially as a gameplay element!

\$\endgroup\$
2

1 Answer 1

2
\$\begingroup\$

My recommendation would be to approximate the surface with 2d wave simulation. That is, you have a plane and each point has a height property defined by the neighboring points and the wave equation. A google search for 2d wave dynamics algorithm gives a lot of papers and applets, so you can go crazy on that.

Getting that information to a 3d model is as simple as moving the vertices of a planar mesh up and down.

Getting the whole thing to influence physical objects will be trickier. I would experiment with applying forces the rigid bodies based on a specific point (center of mass, pivot etc) relative to the water. This point, projected on the water, will be inside 3 points of the water simulation (defining a plane), so we check if it's below or above water level and, if below, apply buoyancy force normal to the plane defined by the three points. You would also need to concern about "aerodynamics", that is how the direction and speed of the moving vehicle influence the dynamics by creating additional forces.

Having said all that, finding the proper algorithm for fluid dynamics is critical. Depending on the size of the world you might need faster implementations, or a way to break calculation into zones etc.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ However, I've seen some videos of this game you posted and I don't think that's simulated at all. I think they have a whole bunch of premade waves they they blend together when appropriate. So maybe you could try something like that too. \$\endgroup\$
    – Diego
    Jan 10, 2015 at 8:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .