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

GameMaker Floating character

conman06

Member
Okay, so I'm trying to program the player's vertical collision. My problem is that the player hovers over the ground, yet it says that it is on the floor. I can assure you that it is not a hitbox problem. Below is the code for vertical collision.
GML:
//Gravity
    if (!place_meeting(x,bbox_bottom + vsp,oWall)) {
        vsp = clamp(vsp,-10,15)
        grounded = false
    } else {
        //Actually falling
        if (sign(vsp) < 0) {
            //Slowfall to adjust position
            if (!place_meeting(x,bbox_bottom + vsp,oWall)) vsp = vsp;
            else vsp = 0;
            vsp = 0;
            grounded = true
            bonus_jumps = max_jumps
            hold_jump = false;
    }
}
I've attached a photo of what the player looks like in the game. (ignore the variables, they're there to help me identify the problem.)
Floating character.png
I've been trying to fix the problem for the past few days, so I hope you can help identify the problem and help me fix it.
 

NightFrost

Member
You don't appear to have any code there that would adjust position on wall collision, to move the player next to wall. Usually the vertical collision check would go something like:
GML:
// If there is a wall instance in range of vsp movement.
if(place_meeting(x, y + vsp, oWall){
    // Move in 1 pixel increments towards vsp direction (hence the use of sign) until wall is reached.
    while(!place_meeting(x, y+ sign(vsp), oWall){
        y += sign(vsp);
    }
    // We're next to wall now, so zero out the vsp
    vsp = 0;
}
// Add vsp to position
y += vsp;
Also, do not mix coordinates and bbox variables in collision checking as there's a little gotcha there: bbox variables are always integers rounded from coordinates, so they can introduce 1-pixel error to collision checks.
 

curato

Member
yeah I do something similar to this suggestion except have a function check the proposed move and if it doesn't work then decreases it by one until it will work then returns that value then I do the move one time.
 

curato

Member
This is the fourth most elaborate way to write "vsp = 0" that I've ever seen.
yeah this
GML:
if (!place_meeting(x,bbox_bottom + vsp,oWall)) vsp = vsp;
else vsp = 0;
vsp = 0;
should have really been more like this if I understand what he was doing, but I don't think it would 100% fix his issue
Code:
if (place_meeting(x,bbox_bottom + vsp,oWall)) vsp = 0;
 

Nidoking

Member
I don't think it would 100% fix his issue
It would not, due to the aforementioned lack of anything that moves the instance to the point of collision before or after halting its vertical speed. However, the logic tree
if condition, do nothing
else set vsp to zero
actually, just set vsp to zero either way

is clearly wrong, but the exact nature of its wrongness isn't always apparent from a first glance.
 
Top