Vertical Collision "slide"

K

kingjabu

Guest
Right, so in my game, I'm going the pretty standard method with collision, and this is the code I'm using
Code:
if(grid_meeting(x, y + vsp, foreground)) {
    if(!grid_meeting(x, y + sign(vsp), foreground)) {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
My question is, how would I go about making the player "slide" across the bottom of a block rather than setting vsp back to 0 making him fall? I want to hold position until the player falls naturally.

Just to try to visualize what I mean:
vsp_ex1.png

So the vsp is set to 0 upon collision, that's what I want to do for the top of course to prevent the player from falling through, however for the bottom, I want the player to slide across until gravity
has an effect on vertical speed. Something like this:
vsp_ex2.png

Any help is much appreciated!
 

Bentley

Member
You might be missing a while loop btw.
My question is, how would I go about making the player "slide" across the bottom of a block rather than setting vsp back to 0 making him fall?
You could not set vsp to 0 and instead let it decrease by gravity.
 
K

kingjabu

Guest
You might be missing a while loop.

You could not set vsp to 0 and instead let it decrease by gravity.
Oh yeah I didn't notice that I was missing the while loop, haha, I was coding a project that I could test stuff on for my main project so I put it together pretty fast.
I'll try that out though, thanks!
 

Bentley

Member
Oh yeah I didn't notice that I was missing the while loop, haha, I was coding a project that I could test stuff on for my main project so I put it together pretty fast.
I'll try that out though, thanks!
Yeah, so when there is a collision, check "if vspd > 0". If it is, you are falling, and if it's not, your are rising. Set vspd to 0 only if your are falling. Something like that might work.

You could also have some sort of stickiness variable that you set when you collide with a ceiling. Set a timer and keep vspd at 0 until the timer ends.
 
Last edited:
Top