r/howdidtheycodeit • u/Vivalavestro • Jun 05 '21
N64 Wave Race Water/Jetski Physics
Hey everybody!
Any ideas how they made the physics for that game because I am absolutly clueless :/
In generel water physics are quite difficult to understand for me (Unreal Engine user here)
31
Upvotes
5
u/speccyyarp Jun 06 '21
Check out this series from Digital Foundry https://youtu.be/V4MMlKhJfGI at 11:30 they examine Wave Race. They don't talk about any specific code but should give you some great insights into the techniques they used.
1
u/inside-loop Jun 08 '22 edited Jun 08 '22
Typical water physics approach for games is a combination of hacks, in that there isn’t any actual fluid simulation or spatial particles like you would see with the actual properties of a liquid, unfortunately a full simulation like that is far too powerful for most triple-A 3D games and our level of consumer technology just isn’t ready for that yet- but we’re getting there!
What most people do is define a 3D object in the world and assign it as a special type along with a water texture. It’s transparent and the geometry on the upper face of the water is a flat mesh. The mesh and the texture itself are modified during runtime by fragment shaders to create the hyperbolic waves which simulate ripples and displacement, these shaders can be used to create large repeating ocean waves like you see in Sea of Thieves and smaller ripples and disturbances dynamically generated when objects intersect with the mesh. There’s an underlying height map that the shader generates when it calculates the waves and displacement, this is then applied to the mesh itself. When an object intersects the water’s surface the shader calculates the height of the ripple/waves that emanate out from the point of intersection. These ripples can be larger or smaller depending on the type of object or depending on the force + size of the disturbance. There’s also the matter of simulating floatation & some minor buoyancy. In most games, objects traveling through the water will match/follow the height of the hyperbolic path of the wave if they’re at the surface. There’s also usually some minor buoyancy added to objects in the water to help simulate bobbing up and down while floating. In cases like with large ocean waves, the water shaders will also simulate sea foam by modifying the texture’s color at some point during wave generation. Then finally to polish it off, throw in some sprite particles textured like water and foam that can be used to simulate ‘splashing’ depending on the event.