• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Collision Question

RyanC

Member
Hi everyone, I've been having trouble with a collision code for weeks and was wondering if I could get some help with it?
The problem is that the player dies too easily.
I only want the player to die if it hits a block in front but it dies even when getting shot into the floor or ceiling.

Code:
    if place_meeting(x,y+sign(gravity),other)
    {
        var v_direction = point_direction(x,yprevious,x,y);
              
        y = yprevious
        move_contact_all(v_direction,-1)
        vspeed = 0
        landed = true

        if place_meeting(x,y+(-gravity*8),other)
        {
            x = xprevious
      
            if Hspeed2 >= 0
            {
                if ! instance_exists(obj_die)
                {
                    instance_create(x,y,obj_die)
                }
            }
            else
            {
                Hspeed2 = game_speed*0.5
            }
        }           
    }
 

NightFrost

Member
I'm not sure what that code block is trying to achieve at the end. It reads:

If there is a collision vertically in the direction of the gravity variable, move back a step and then move into contact, set vspeed to zero and landed to true.
If the previous was true, and there also is a collision in the opposite vertical direction, but eight times more distant, move to previous horizontal location.
If the previous was true, and Hspeed2 is greater or equal to zero (whatever this means), spawn an instance if it doesn't already exist. Otherwise set Hspeed2 to half the game_speed.

If your game_speed is greater or equal to zero, and this bit is the only one that adjusts Hspeed2, it will always be >= 0 after both collisions are true, and the instance create runs as soon as both collisions are true a second time (but if your Hspeed2 is initialized to zero, then this happens on the first time). Note that the collisions will both be true when you are close enough to objects, as they are not gated by any movement speed checks, proximity alone is enough.
 
Top