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.