1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GML 2D Dynamic Water and Liquids (Waves)

Discussion in 'Tutorials' started by Zack, May 4, 2018.

  1. Zack

    Zack Member

    Joined:
    Jun 20, 2016
    Posts:
    14
    GM Version: GameMaker Studio 1.4 and GameMaker Studio 2
    Target Platform: All
    Download: Source Code: https://github.com/zbanack/TSE-dynamic-water
    Links: See embedded YouTube video

    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.


    [​IMG]
     
    Last edited: May 31, 2018
    Rukola, pagou, NeZvers and 4 others like this.
  2. The Reverend

    The Reverend Member

    Joined:
    Sep 8, 2016
    Posts:
    558
    Great tutorial.
    Thanks mate!
     
    Zack likes this.
  3. mog-frarol96

    mog-frarol96 Member

    Joined:
    May 13, 2018
    Posts:
    7
    Wondering if it is possible to use this in a top-down environment?
     
  4. Zack

    Zack Member

    Joined:
    Jun 20, 2016
    Posts:
    14
    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.
     
    slojanko and The Reverend like this.
  5. mog-frarol96

    mog-frarol96 Member

    Joined:
    May 13, 2018
    Posts:
    7
    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!
     
  6. Nico (T.U.S.L video game)

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

    Joined:
    Apr 3, 2018
    Posts:
    2
    Great Tutorial!! I was wondering how to make this interact (collision) with an obj_player ? Thanks!!
     
  7. Zack

    Zack Member

    Joined:
    Jun 20, 2016
    Posts:
    14
    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
    */
    }
     
  8. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,376
    moves like jelly for me.
     
  9. Nico (T.U.S.L video game)

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

    Joined:
    Apr 3, 2018
    Posts:
    2
    :) thanks, brothaa Zack!!! good stuff mate!!
     
  10. Zack

    Zack Member

    Joined:
    Jun 20, 2016
    Posts:
    14
    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: May 31, 2018

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice