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.
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.