GML2D Dynamic Water and Liquids (Waves)

Zack

Member
GM Version: GameMaker Studio 1.4 and GameMaker Studio 2
Target Platform: All

Summary:
A video lesson where I go over the logic and code behind making 2D dynamic water (waves). Although this water won't follow the real-world physics of liquids as we're using springs and elasticity to achieve the effect, it certainly adds flair to a game.

In-depth logic explanation and tutorial:

Update -- Adding Collisions with objects: You can find a comment I posted on the first page of this forum post with a Google Drive link on how to add basic player collision and splashing.

Last edited:

Great tutorial.
Thanks mate!

M

mog-frarol96

Guest
Wondering if it is possible to use this in a top-down environment?

Zack

Member
Wondering if it is possible to use this in a top-down environment?
I don't see the effect transitioning well to top-down unless you use it as a shoreline. For top-down water, Daniel Shiffman's approach might be better. Note that the video isn't in GML, but the logic translates.

M

mog-frarol96

Guest
I don't see the effect transitioning well to top-down unless you use it as a shoreline. For top-down water, Daniel Shiffman's approach might be better. Note that the video isn't in GML, but the logic translates.
Sorry, was tired yesterday after too long doing web development. I meant isometric instead of top-down, but the video you linked me were very interesting and informative towards a solution for top-down water ripples, cheers!

N

Nico (T.U.S.L video game)

Guest
Great Tutorial!! I was wondering how to make this interact (collision) with an obj_player ? Thanks!!

Zack

Member
Great Tutorial!! I was wondering how to make this interact (collision) with an obj_player ? Thanks!!
I'd use the collision_line function in the first for loop in the Step Event, replacing our mouse_check_button and point_in_rectangle conditions:
Code:
if (collision_line(x1, y1, x2, right_y1, OBJECT_NAME, true, false)) {
/* object has now entered the water
... maybe set a variable named OBJECT_NAME.in_water to true
*/
}

zendraw

Member
moves like jelly for me.

N

Nico (T.U.S.L video game)

Guest
thanks, brothaa Zack!!! good stuff mate!!

Zack

Member
How to add collisions with objects...

Because of the PMs I'm getting, here's a source code with basic player collision and splashing: https://drive.google.com/file/d/172rMWCQmyLJOeBMJDBS_vamOHV1OV6iy/view

It's not the cleanest implementation, but it's a quick way to get a player object, obj_player, to have an "inside water" state. The player follows the cursor and turns blue when it's considered in water -- replace these with your own movement and swimming code.

Last edited: