M
MrSquishy
Guest
Hey!
I'm new here, so bare with me
- I have recently started working in GM, and I've enjoyed it immensely so far.
Here's my question.
I see to be having some collision(?) problems with my character.
Sometimes when I jump and land on a surface there's a small pixel gap (1-3 usually) between the character and the surface.
Also, this is the first game I've tried to make.
It's obviously nothing, but it's just me training myself.
I jump down: (GAP!)
Then, I fall from the left ledge and land: (NO GAP!)
It's random, too. I can't seem to purposely replicate the error, it just... happens.
Here's my code for the Step event:
Thanks in advance for any help! If anybody needs any more information, I'll provide it.
I'm new here, so bare with me
- I have recently started working in GM, and I've enjoyed it immensely so far.
Here's my question.
I see to be having some collision(?) problems with my character.
Sometimes when I jump and land on a surface there's a small pixel gap (1-3 usually) between the character and the surface.
Also, this is the first game I've tried to make.
It's obviously nothing, but it's just me training myself.
I jump down: (GAP!)
Then, I fall from the left ledge and land: (NO GAP!)
It's random, too. I can't seem to purposely replicate the error, it just... happens.
Here's my code for the Step event:
Code:
///Movement Engine & Stretching
//Get the player's input
key_right = keyboard_check(ord("D"));
key_left = -keyboard_check(ord("A"));
key_jump = keyboard_check_pressed(ord("W"));
if (key_jump = 1 && place_meeting(x,y+1,obj_floor)) {
draw_yscale = 1.5;
draw_xscale = .75;
audio_play_sound(snd_jump,0,0);
instance_create(x,y+16,obj_jumpDust);
}
if (place_meeting(x,y+1,obj_floor) && land = 0) {
audio_play_sound(snd_land,0,0);
instance_create(x,y+16,obj_jumpLand);
land = 1;
}
if (!place_meeting(x,y+1,obj_floor)) {
land = 0;
}
//React to Inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;
//Jumping & Sprite Changes
//Sprite Stationary
if (place_meeting(x,y+1,obj_floor) && move = 0)
{
vsp = key_jump * -jumpspeed;
sprite_index = spr_player;
//Sprite to LEFT
} else if (place_meeting(x,y+1,obj_floor) && move = -1) {
vsp = key_jump * -jumpspeed;
sprite_index = spr_playerLeft;
//Sprite to JUMP LEFT
} else if (!place_meeting(x,y+1,obj_floor) && move = -1) {
sprite_index = spr_playerJumpLeft;
//Sprite to RIGHT
} else if (place_meeting(x,y+1,obj_floor) && move = 1) {
vsp = key_jump * -jumpspeed;
sprite_index = spr_playerRight;
//Sprite to JUMP RIGHT
} else if (!place_meeting(x,y+1,obj_floor) && move = 1) {
sprite_index = spr_playerJumpRight;
//Sprite to JUMP (stationary)
} else if (!place_meeting(x,y+1,obj_floor) && move = 0) {
sprite_index = spr_playerJump;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_floor))
{
while(!place_meeting(x+sign(hsp),y,obj_floor)) x += sign(hsp);
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_floor))
{
while(!place_meeting(x,y+sign(vsp),obj_floor)) y += sign(vsp);
vsp = 0;
}
y += vsp;
//Strech Lerping
draw_xscale = lerp(draw_xscale, 1, .1);
draw_yscale = lerp(draw_yscale, 1, .1);
if (place_meeting(x,y+1,obj_floor) and !place_meeting(x,yprevious+1,obj_floor)) {
draw_xscale = 1.25;
}
Attachments
-
14.1 KB Views: 0