waves and splashes

May 7, 2009 at 9:21 AM

Im trying to make my water produce wavesand splashes whenever an object falls into it, and Ive half got it working.

The problem Im having is that an object will penetrate the water just a tiny bit, and cause a disturbance equal to the objects velocity / 20, but then the new disturbance will leave the object exposed, causing another disturbance straight afterwards and so on and so on.

Objects have a flag saying if theyre in the water or not and this get updated each frame.

Has anyone done this in their game, or have a better way, or any sort of idea?

May 7, 2009 at 4:30 PM
@robertdodd: I have just nearly finished the XNA Water Demo. Take a look at the latest change set and feel free to ask me any questions until I done writing all the source code documentation. Probably by tonight I will have added real-time control of the waters properties and objects masses so those touchy values can be quickly adjusted and then used in your own game.

Also anyone that has done some custom rendering please take a look at my rendering code and let me know if I am doing anything wrong or any methods to speed it up. It runs great on my desktop and at like 2 fps on my laptop.
May 8, 2009 at 9:51 AM
Edited May 8, 2009 at 9:51 AM

Hi matt


Please explain the equation you use to calculate the disturbance amount.

And instead of using the bodies velocity as the displacement, wouldnt it be better to use the bodies velocity at that point as the displacement?

And also, it disturbs the water even underwater, Id like that not to happen because it allows me to make splashes when things fall in.


It made crazy waves when I used it in my code, but that might have to do with the drag and density etc. of my water. Thats why I want to understand the equation you used.


Thanks a lot.

May 8, 2009 at 11:26 AM



Hi Robert,

I added this code in the Update method of the FluidDragController right after FindVerticesInFluid().

                foreach (Vector2 v in _vertices)
                    float disturb = _geomList[i].Body.LinearVelocity.Y;

                    if (disturb > 100.0f)
                        _fluidContainer.Disturb(v.X, (disturb * (float)Math.Sqrt(_geomList[i].Body.Mass)) / 5000.0f);

Don't ask how I came up with that formula I just kept trying different stuff until it started working. Also I understand the bodies do make disturbance even when underwater. I need to change some more code to prevent this.

Water is very touchy, you really have to fine tune all the values to get the effect you want. I've added real-time control through the keyboard you just need to check out the Input functions to see which keys do what until I finish it.

I hope this helps.

May 9, 2009 at 4:41 PM

@robertdodd: Just wanted to update you, I changed how I was approching the problems we were having. Please check out the latest source and review the changes I made. I still need to tinker a little but it seems way more realistic now.

May 10, 2009 at 8:10 AM

Thanks a lot Mat, Ive adapted it to my engine and Im not having those problems I had before, so thanks again.