Movement bug help needed

I've scripted movement but when i tap the left key and right key really fast with my player it bugs trough the collision i've made in the game
I've checked hit box, and im really new to scripting so - i cant wrap my head around the issue so! (learned scripting yesterday) here is what i've come up with by watching totourials and gotten some help of my friend, and googling
ALSO when i press both left and right key my player dissapears which also goes trough all the collision

ALSO if you have something to add or something that could be better or something that seems way complicated written, feel free to make some suggestions and tell why and what cause i am new - and wanting to learn ty

Here is the scripts for movement, collisions and some animations for the player

Code:
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);
//movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;


if (place_meeting(x,y+1,obj_solid)) and (key_jump)
{
    vsp = -7;

}

//Horizontal Collision
if (place_meeting(x+hsp,y,obj_solid))
{

    while (!place_meeting(x+sign(hsp),y,obj_solid))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
}

x = x + hsp;

//vertical Collision
if (place_meeting(x,y+vsp,obj_solid))
{
    while (!place_meeting(x,y+sign(vsp),obj_solid))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
}
y = y + vsp;

//animation til player

if (key_right + key_left !=0)
{
image_xscale = move
sprite_index = sprite2
}
else
{
    sprite_index = spr_player
}



if (place_meeting(x,y+1,obj_solid))
{
    grounded = true;
} else {
    grounded = false
}

//Draw Event
if (!grounded) {
    sprite_index = midair;

    if (image_index >= image_number-1) {
        image_index = image_number-1;
    }
}
else {
    sprite_index = sprite2;
}
 
Last edited:
Top