Legacy GM 2D Platformer - Feet sticking into ground?(SOLVED)

X

Xahn

Guest
Hello. I am creating a 2D platformer and I am having a little issue with my character standing on surfaces.

This seems to happen at random and is purely an aesthetic concern as the player does not get stuck or is movement ever prevented(which I don't understand). At worst, it can cause the player to be drawn at an odd position which results in hideous stretched pixels.


This is my jump code:


if gamepad_button_check_pressed(0,gp_face1) and ground=1
{
vspeed=-4.1
sound_play(choose(snd_jump,snd_jump2))
duck=0
if dashin=0
{
jump=1
}
else
{
jump=2
}
}

Code for releasing the jump button:


if !(gamepad_button_check(0,gp_face1)) and vspeed<0 and ground=0
{
vspeed=0
}


Code in collision event with the floor object:

vspeed=0
move_contact_solid(270,30)


Code for gravity in the step event:


//Falling
if (place_free(x,y+1)
{
ground=0
gravity=0.17
}


//Landing
if !(place_free(x,y+1))
{
ground=1
gravity=0
}

//Cap
if vspeed>8
{
vspeed=8
}


All sprites have their origin at the lowest point, and my character uses a rectangle as a mask regardless of his current animation. When his feet stick into the floor, his y variable is effected.

Here I use "draw_text" to show his y variable.


Desired look:


Undesired sinking:



My floor object is a 16x16 solid square object.

I have also tried to add this code which did nothing:

if !(place_free(x,y-1)) and ground=1
{
y-=1
}


Anyone know why this would happen? I also use hspeed to control his movement if that matters.

Any advice on how to avoid this would be greatly appreciated. Thank you.
 

Jakylgamer

Member
are all the sprites the same size in height ?
if not that could be the issue
double check to make sure all the sprites are the same size and have the same origins

also you can do this for less coding
Code:
gravity = place_free(x,y+1)*0.17;//this will set the gravity 
ground = place_meeting(x,y+1,obj_ground);//will set ground to 0 or 1
 
X

Xahn

Guest
are all the sprites the same size in height ?
if not that could be the issue
double check to make sure all the sprites are the same size and have the same origins

also you can do this for less coding
Code:
gravity = place_free(x,y+1)*0.17;//this will set the gravity
ground = place_meeting(x,y+1,obj_ground);//will set ground to 0 or 1


All origins are placed at the very bottom of all sprites. All sprites can not be the same size unless you mean add a transparent border around every one, since a cropped crouching animation for example will be shorter than a jumping or standing animation.
 

Jakylgamer

Member
i mean to where all sprites are the same size but the image can be any inside the boundaries of the image size
like lets say all sprites are 100 x 100 you would need to align all those sprites up inside the 100 x 100 image to where all sprites seamlessly line up. ill use this image as an example

see how all the sprites are centered and aligned within the 200 x 200 sprite size? thats what i mean.
 
X

Xahn

Guest
Changed the size of all sprites to 100x100 with an origin of X: 50 and Y: 75, then used "shift" under the transform menu to move the sprites into the desired positions.

It still persists as it did when all sprites were trimmed with a border size of 0.

...... The solution was view size. o_O

Changing the view size from 400x225 to either 384x216 or 512x288 solves the problem. This isn't the first time using low res 16:9 view sizes has caused problems for me. 400x225 was the desired camera, but I will have to change if it causes problems.

Thank you for taking the time to help. Much appreciated.
 
Last edited by a moderator:

RangerX

Member
Views doesn't have anything to do with it.
If changing the view size did make your character appear at the right place, this means there's a scaling issue somehow in your game. And this can be properly debugged. There's no reasons a low res 16:9 game to not display properly.
 
X

Xahn

Guest
Views doesn't have anything to do with it.
If changing the view size did make your character appear at the right place, this means there's a scaling issue somehow in your game. And this can be properly debugged. There's no reasons a low res 16:9 game to not display properly.
What would you suggest?
 

RangerX

Member
I would keep my view 400x225 and debug elsewhere.
There's multiple possible reasons for your character ending up 1 pixel in the ground. It can happen because of some fraction rounding (by the way, why having "vspeed-=4.1" ?? make it "4")
So there's multiple possible solutions. Have you tried rounding your Y position in some "end step" (given your movement and all that is done in normal step).
Another approach could be to detect the collision with an object yourself with a collision line. I find this a bit more explicit and controllable.
You could also have a move outside solid (would not recommend but still).
Regardless your character you could also draw your character at a rounded position. This could be an easy solution if the fact your character being 1 pixel in the ground doesn't impact the gameplay or create bugs.
 
Top