GameMaker [Solved]Why is my player feet below the floor?

V

VaporaLight

Guest
upload_2019-11-14_12-0-3.png
White rectangle is measured based on the collision mask of the player. Both the player and the ground are marked solid. How do I prevent the player's feet from being under the ground tile?

EDIT:
this is my code that affects gravity

// Gravity Effect
if(!place_meeting(x,y + 1,oGround))
{
y += baseGrv;
}

code that affects ground collision

//Ground Collision
if (place_meeting(x, y + 1, oGround))
{
//show_debug_message("Touch Ground");
hasTouchGround = true;
baseGrv = 0;
if(!global.key_jump)
{
hasRecentlyJump = false;
}
}
else
{
//show_debug_message("Not Touch Ground");
hasTouchGround = false;
baseGrv = 5;
}
 
Last edited by a moderator:

TheouAegis

Member
If they were marked as solid and you had a Collision Event, then you shouldn't be above the ground. So your code did something wrong.
 
V

VaporaLight

Guest
@TheouAegis they are marked solid but the ground doesn't have a collision. What can i change in the code? and what do u mean by I shouldn't be above ground?

@BattleRifle BR55 Ok i shouldnt use solids.
So the logic would be if player.bbox_bottom.y > ground.bbox_top.y = "player's Y position is pushed back to make it less or equal to the ground Y collision"?
 

TsukaYuriko

☄️
Forum Staff
Moderator
If you use solid, know that you entirely surrender control of collision handling to the engine. solid works if - and only if - a Collision event between an object and a solid object exists. Upon registering a collision with a solid object's instance, the other object's instance will be re-positioned to its previous position. It's equal to this code - refer to the documentation of solid for reference:
Code:
if (place_meeting(x, y, obj))
{
    x = xprevious;
    y = yprevious;
}
If you want exactly this, using solid will lead to the desired results.
If you don't want exactly this, for example if you're trying to have precise collisions, don't use solid.
In your example, using or not using solid should make no difference at all as you don't have a Collision event with the solid object. solid should therefore be doing nothing at all in your case.

@TheouAegis they are marked solid but the ground doesn't have a collision. What can i change in the code? and what do u mean by I shouldn't be above ground?
I assume it was meant to be "shouldn't be below* the ground".
To link into what I explained above: solid does nothing due to your current implementation. If it did something, it would ensure that it is literally impossible for colliding instances to overlap it. Your instance is overlapping it, so it either has a collision mask that's smaller than its visible sprite, or solid is doing nothing because there is no Collision event. Therefore, if it was solid and registers collisions, it shouldn't be possible for the player to be below the ground - so it's not solid or you didn't register collisions.


Either way, disable solid.


You should implement entirely custom collision handling. What you're doing so far is stopping gravity when there is ground below the player's feet, but that alone won't cut it. Your player is most likely moving at vertical speeds which are not exactly equal to 1, so you'll likely end up a few pixels or a fraction of a pixel above the ground in one step, and then you'll be a few pixels below it already in the next step.

This is where your code would have to intervene - register a collision and move the player upwards in increments of 1 pixel until it's no longer stuck in the ground. Preferably, round the player's position in the process so they're not at fractional coordinates, but land pixel-perfectly on the ground.
 
V

VaporaLight

Guest
@TsukaYuriko Great idea, i'll try that. Indeed it is true that before your reply, i had the ground and the player marked as solid but neither of them have a collision event and the gravity is 7
 
Top