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

Legacy GM Sprite sometimes floats one pixel from the ground

B

Breno Baiardi

Guest
I ve been doing this game for some months, and the colisions were fine. My character used to jump and fall perfectly, without floating or passing trough the ground pixels.

However after some time i realized it is sometimes (only sometimes) walking and standing one pixel over the ground.

In my code i am using the place_meeting function to find if my y+vertical_speed will encounter the obj_wall, and to correct this i ve been trying to use the method were we use the sign(vsp ) to not going too far when falling, but its stopping before touching the object..

(sorry for grammar, brazilian here)


Here I have some code. I would really apreciate if someone helps


///Movimento

KEY_LEFT = -keyboard_check(vk_left)
KEY_RIGHT = keyboard_check(vk_right)
KEY_JUMP = keyboard_check_pressed(vk_space)

if !dead{
move = KEY_RIGHT+KEY_LEFT
hsp = move * movespeed
}

if (move!=0){
image_xscale = move
global.side=move
}

//Verificação de chão
if (place_meeting(x,y+1,obj_wall)){
vsp=0
grounded=true
}else{
vsp+=grav;
grounded=false
}

//queda arrumando pixel
if (place_meeting(x,y+vsp,obj_wall)){

var cc;
cc=vsp+1;
while(!place_meeting(x,y+1,obj_wall) and cc>=0) {y+=1;}
grounded = 1;
vsp = 0;

}



//verificação de colisão paredes
if(place_meeting(x+hsp,y,obj_wall)){
while(!place_meeting(x+sign(hsp),y,obj_wall)){
x += sign(hsp);
}
hsp=0
}

//animação somente quando o jogador se move
if grounded and !dead
{
if move!=0{
sprite_index=spr_player_move
image_speed = 0.3;
}
else
{
image_speed = 0.05;
sprite_index=spr_player_idle
}

//PULAR
if (KEY_JUMP){
vsp=-jumpspeed
}
}
else if !dead{
sprite_index=spr_player_move
image_speed = 0;
image_index=0;
if vsp>0{
image_index=2;
}
}


// Pulinho vs pulão
if(keyboard_check_released(vk_space))and(vsp<0){
vsp=0
}

//inrcrementação de movimento
if !dead{
x += hsp
}
else{
sprite_index=spr_player_die
image_speed=0.05
}
y += vsp
 
B

Breno Baiardi

Guest
I checked the sprite, i am using another sprite as mask

I tought it should be the mask, but i made a test with another sprite, a white square with mask same as sprite.

With this the sprite sometimes crosses the line od ground, and sometimes fit in the right place. I dont think the problem is the sprite, because it sometimes works, and sometimes not.
It should be a problem in the way i m controlling the fall and the collision
Here i have the verification for the grounded stat and de falling code:


//Verificação de chão
if (place_meeting(x,y+1,obj_wall)){
vsp=0
grounded=true
}else{
vsp+=grav;
grounded=false
}

if (place_meeting(x,y+vsp,obj_wall)){

var cc;
cc=vsp+1;
while(!place_meeting(x,y+1,obj_wall) and cc>=0) {y+=1;}
grounded = 1;
vsp = 0;

}
 
Top