Water Physics Mod

An attempt to add liquid like physics to Doom 3. It adds buoyancy properties to rigid bodies and ragdolls (AF's) using defined density and...


Do not refresh or leave this page!

File Description

An attempt to add liquid like physics to Doom 3. It adds buoyancy properties to rigid bodies and ragdolls (AF's) using defined density and viscosity.

In a later version I think it's be fun to add a wavey surface that's affected by object colliding but I can't really think of a fast way to do this so if anyone's got any ideas I'm listening.

I'm still stuck with a DirectX 8 video card so I don't see any of the fancy vertex programs or anything but I know there are some good ones out there for anyone interested in looking around. What I've provided is a slightly modified version of someone else's work (credits at the bottom). It's really only a place holder.

How to play

1. make a a folder Doom3/waterphysics 2. unzip the contents of the zip file into that folder 3. Start doom and choose "Water Physics" from the mods menu 4. Go to console (CTRL+ALT+~) and type "map test_water" and play around a little

I usually play with a key bound to "toggle g_dragentity 0 1" to help move stuff around but it's up to you.

Read More

Download 'water_physics_mod_v1.zip' (2.38MB)

Water Physics Mod (v1.0)
Lloyd Markle
21:50 03/05/2005

Table of Contents
	1. Water Physics (in a nutshell)
	2. Changes
	3. Notes/Unresolved issues
	4. idLiquid (in depth)
	5. Source code list
	6. Additions credits

1. Water physics (in a nutshell)

The way this works is that now physics objects have a idPhysics_Liquid * inside them. This field is generally NULL until the object collides with a liquid and then it is set.  By doing water this way, each object is responsible for it's own actions in the water.  This may not be the best way of going about this whole thing but it gave me pretty good results so I thought I'd toss it out there for the world to see and play with.

Thanks to inolen for the player getting out of the water code.  I could never really seem to get it working right.

2. Changes

Added 1 class: idPhysics_Liquid
	- mainly for storing density/viscosity information
	- perhaps later expand to manage a 'wavey' surface (?)

Moved idLiquid from Misc -> idLiquid (in it's own files)
	- Several additions to idLiquid class
	- This class is mainly for doing entity stuff with liquids (splashing, spawning, saving, etc)

Added 2 events to entity (for scripting):
	getMass(int) - returns the mass of the specified body (and reduced mass if body is in water)
	isInLiquid() - returns 1 if the entity is in water (maybe useful to script AI swimming?)

Added 2 cvars (help strings available from in game)

There are numerous additions to idLiquid.def and it may be useful to examine test_water.map to get a bit of an understanding of how to make use those additions.

Added an env_ragdoll_mancubus - just for fun.

If you spawn vehicles, make sure they have the key 'fixedDensityBuoyancy' '0' otherwise things get a little messy... this has to do with changing the AFBodies mass when they're in liquid, not sure how to fix it.

Added several snd_ defs to various definitions so that object play sound when they splash.

Added 10 or so particles, they're very simple particles you can examine them in /particles

Added a water splash sound.

A list of modified files can be found at the bottom.  I didn't // my name or anything to note my changes
but a search for 'water' or 'buoyancy' should give you any changes I've made.

3. Side Notes/Unresolved issues

1) Notes on AF fixedDensityBuoyancy: This mode is slower to calculate but bodies rest sooner, I think it's a nicer effect but it has some artifacts (try shooting a floating body, it doesn't really seem natural). The artifacts are due to the AFBodies being lighter in water but I'm not sure how to fix this.

2) Another issue I couldn't resolve was spawning particles based on the normal of the surface they hit.  Basically, I'm just not sure how to go from an idVec3 to an idMat3 and still perserve the rotation.  If anyone wants to add this please feel free to do so.

3) Another thing I'm not happy with is the way actors splash when they're in water. Basically they splash a particle if I flip a coin and get heads.  This is okay but it would be better if it could somehow be related to the actors legs and be timed properly. Originally I tried using footstep sound but not all bad guys make use of that event and there's not collision information available from it so I don't know where to spawn the  particle.  

Lastly, particles aren't spawned on the surface but at the entity origin.  This is because the collision 
information derived from Event_Touch is useless.  This needs a fix (as noted in the code)

4) Carefuly spawning a vehicle, for some reason they don't work properly in fixedDensityBuoyancy mode (for explanation of what this is, see below).  I think it has something to do with changing the AFBody mass when the object is in water but I'm not totally sure why they behave as they do.  If you want to see this in action, use 'spawn env_buggy fixedDensityBuoyancy 0' and see what happens (assuming you've got all the proper vehicle assets).

5) For some reason r_skipParticles doesn't skip splashes on the water.  This may be because I spawn a splash when the entity collides.  I'm not totally sure but I have a feeling that I'm mixing entity and physics calculations and this is why I'm getting the strange result.  Oh well, who plays with r_skipParticles turned on anyway?

6) When calculating the percentage of the body in water sometimes it will accidentally calculate 0 if the body is near the bottom of the liquid.  This is really only noticeable with AF's (or a really odd shaped rigid body) so I didn't feel it was necessary to change but a good way to fix it (a lazy way) is to just make the liquid deeper than the floor of the map that way the body never gets close to the bottom of the liquid.

4. idLiquid (in depth (pardon the pun))

This entity is much more complicated than before.  Firstly it is given a name.  By default it's'water' but you can name it whatever you like (test_water.map has a liquid named 'toxin').  This is used to help entities determine which type of splash they should generate when colliding with the liquid.  This system is somewhat complicated but there is good reasoning.

Originally I thought it made sense to let the liquid handle all splashes and you simple define those splashes for that liquid.  This was because liquid was supposed to be general and thus you wouldn't want
every entity to know about every type of liquid.  By giving it a name, you can define specific splashes in
the entity so you control which types of liquid an entity knows about.  If the entity doesn't 'know' a liquid then the liquid will use one of it's default splashes.

Rules for defining splash sounds are similar to defining particles only the liquid doesn't have a default sound for the entity.  This is because sounds are played by the entity and not by the liquid so they have to be in the entities decls.

As for the actual physics you can define density and viscosity.  Density behaves as you would expect and viscosity is essentially a way to define friction in the liquid.  I'm not a physics major and I don't really understand what units viscosity would be measured in.  I found it gave me a good effect when I use it like a friction scalar.  Essentially every body moving through the liquid will use linearFriction*liquidViscosity where it would normally use linearFriction.  Anyway, the default value, for viscosity is 3.0 and this looks relatively close to water (default density 0.01043).

I tried to give examples of usage of the liquid system.  For instance, env_ragdoll_hazmat has some defines in it's .def file so now it 'knows' about water with it's 'snd_water' and 'smoke_water' keys.  I altered some of the other entity defs so if you're entity doesn't play a sound, check the .def file and make sure one is defined.  There are no sounds defined for toxin so nothing will make a sound when it splashes.  This can be changed by adding snd_toxin to an entity def with the appropriate sound shader info.

fixedDensityBuoyancy is a way to simulate a bodies density.  I found it more realistic if I apply a single density to every body.  This way they float uniformly (pretty close to uniformly anyway) and you can change their density if you'd rather the body sink.  However, to accomplish this effect I had to 'temporarily' change the AFBodies mass so that it's spatialInertia didn't get screwed up.  For some reason this screws up the vehicles and I'm not sure why (perhaps because they're wheels are motors?).  Anyway, if you want to spawn vehicles the best way to do it is with fixedDensityBuoyany 0 and define a scalar for the gravity on the vehicle once it's in water, for example:

	spawn env_buggy fixedDensityBuoyancy 0 liquidDensity 0.1

Will spawn a vehicle that will sink at 0.1*gravity.  If you'd rather it float define liquidDensity to be negative.

5. Modified files
	Physics			.h	(basic water checking interface)
	Physics_Actor		.h/.cpp	(took player waterlevel info and put it here)
	Physics_AF		.h/.cpp	(added buoyancy stuff)
	Physics_Base		.h/.cpp (added functions to check if in water)
	Physics_Liquid 		.h/.cpp	(physics for the liquids)
	Physics_Monster		.h/.cpp (set/reset waterlevel)
	Physics_Player		.h/.cpp (removed player waterlevel info, help player get out of water (thanks inolen))
	Physics_RigidBody	.h/.cpp (added buoyancy stuff)

	AF			.cpp	(setting buoyancyScalar)
	Entity			.h/.cpp	(added 2 events)
	game_local		.h	(added Liquid.h, Physics/Physics_Liquid.h)
	Liquid			.h/.cpp (liquid entity)
	Misc			.h/.cpp (removed idLiquid from here to it's own file)
	Player			.cpp 	(added water airlessness)

	SysCvar			.h/.cpp (added cvars rb_showBuoyancy, af_useBodyDensityBuoyancy)

6. Additional Credits
Water Materials/Textures by Alex Jeffrey (water_source_v10.zip)

splash.wav from http://www.crews.org/curriculum/ex/compsci/webresources/sounds/
watersplash.wav from http://www.partnersinrhyme.com/soundfx/watersounds.shtml
watershark1.wav from http://www.partnersinrhyme.com/soundfx/watersounds.shtml
waterfall1.wav from http://www.partnersinrhyme.com/soundfx/watersounds.shtml

Read More

Comments on this File

There are no comments yet. Be the first!

Lloyd Markle

50 XP

Registered 8th May 2005

1 Files Uploaded

Share This File
Embed File