GMS 2 Fake 3d Collision in Beat 'Em Up

Discussion in 'Programming' started by The Astronaut, Feb 23, 2018.

  1. The Astronaut

    The Astronaut Member

    Joined:
    May 11, 2017
    Posts:
    54
    In the beat 'em up I'm making, I have a variable (z) that I use to give the illusion of things rising up off of the ground ( This should give you the idea: https://yal.cc/top-down-bouncing-loot-effects/ ). The problem I've encountered is in trying to add basic collisions on this axis. What I want to happen is if there is a solid with a z greater than the players (lower down), the player can jump over/onto it, and be at that z level, and if the solid's z is less than the players (higher up), the player collides with it. I've made several semi-successful attempts at this, but they all seem over-complicated, and also don't work with more than one z level besides 0.

    My code so far:
    Code:
    
    // I use custom hitboxes, so "x1" is the left of the hitbox, "y1" is the top, "x2" is the right, and "y2" is the bottom
    
    // "bw" and "bh" are the width and height of the hitbox respectively
    
    // "z" is the distance from the ground, 0 being default, the lower the higher off the ground
    
    // "ground_z" is the z of the ground, so what the z should be colliding with. This is what should change for collisions
    
    
    
    /// Normal Collisions (I only included right side for the sake of space, but all of the other directions work the same way)
    
    //Right
    if (xvel>0)
    {
        co = noone;
        co_d = abs(xvel);
      
        with (obj_solid)
        {
            if ((y1<other.y2) and (y2>other.y1) and (x1<=(other.x2+other.xvel)) and (x1>=other.x2))
            {
                var _d = (x1-other.x2);
                if _d<other.co_d {other.co=id; other.co_d=_d;};
            }
        }
      
        if (co!=noone)
        {
            x2 = co.x1;
            x1 = x2-bw;
            xvel = 0;
        }
        else
        {
            x1 += xvel;
            x2 += xvel;
        }
    }
    
    
    
    ///My Z collision code so far (I've tried combining this with the normal collisions to mixed results)
    
    with (obj_solid)
    {
        if ((z >= other.z) and (y1 < other.y2) and (y2 > other.y2) and (x1<other.x2) and (x2>other.x1))
        {
            other.ground_z = z;
        }
        else
        {
            other.ground_z = 0;
        }
    }
    
    
     

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