Saturday, May 12, 2007

Using Wave Physics to Render Water

I was going through a list of games that I've programmed recently and was reminded about Dynamite Fishing, a game we (at Electrotank) created for Comedy Central. For that game I programmed a series of wave physics classes that shows waves moving through water at a side view.

I had fun creating that and thought that I'd rewrite it a little more cleanly for ActionScript 3 and make the source available. It allows you to inject waves at any x position with any amplitude. Waves obey superposition - that means that you can continually inject waves and they'll add/subtract each other to produce the appropriate result.

In the source provided you can specify any DisplayObject to show up and float in the water.

Download source

In the example below you can just click anywhere to inject a wave. Notice too that the water never quite settles down. That's because I set it up to inject a small disturbance at random intervals.

CLICK





6 comments:

Anonymous said...

Umm... Awesome!

-Steve

Anonymous said...

Hmmm, can I use this sourcecode in my games?

Jobe Makar said...

Yes.

Paul said...

Very nice. Thanks for sharing.

Vern said...

just wanted to again say...thanks for sharing some awesome code!

Anonymous said...

Wicked. Cool of you to share.