• 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!

A better way to do vertical collision?

lamatoast

Member
Is there a better way to do vertical collisions? because when use this way, it sometime draws the player one pixel into the ground and it's driving me crazy.
GML:
vsp += grv

if place_meeting(x,y+vsp,obj_wall)
{
    while !place_meeting(x,y+sign(vsp),obj_wall)
    {
        y += sign(vsp)
    }
    vsp = 0
}

y += vsp
 
Last edited:

Slyddar

Member
Are you using different sprites for in the air and on the ground, and if so are their origins and masks aligned? Try using the same mask for both by changing the object mask to the ground sprite.
 

TailBit

Member
You could store the fraction value in a separate variable before doing the collission check vfrac = frac(vspd);, then remove it from vspd so vspd is a whole number before the calculation vspd = abs(vspd)*sign(vspd), you add the old fraction value the same place you add gravity vsp += grv + vfrac;
 
Try replacing "y += sign(vsp)" with "y = floor(y) + 1" if you're going down and "y = ceil(y) - 1" if you're going up and you might not have to do anything else
 

Slyddar

Member
Try replacing "y += sign(vsp)" with "y = floor(y) + 1" if you're going down and "y = ceil(y) - 1" if you're going up and you might not have to do anything else
Just wondering if you have tested that change before?

In answer to the OP, if you run tile collisions, once a collision occurs, movement to the tile is in integers, so you end up with perfect collisions.
 
Last edited:
Top