I can't jump when i press up, and left at the same time

by Gameboy The Collector   Last Updated April 15, 2018 23:13 PM

///Get player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);
key_jump_held = keyboard_check(vk_space);
key_shoot = keyboard_check(ord("D"));

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x, y+1, Obj_Floor))
{
 vsp = key_jump * -jumpspeed;
}

if (vsp < 0) && (!key_jump_held) vsp = max(vsp,0)

//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;

//Animate
if (move != 0) 
{
 image_xscale = move;
}

if (place_meeting(x, y+1, Obj_Floor))
{

 if (move != 0) 
 { 
  sprite_index = CalvinWalking;
  image_speed = 0.07;
 } 

 else 
 {
  sprite_index = CalvinStanding;
  image_speed = 0.025;
 }
}

else
{
 if (vsp < 0) sprite_index = CalvinJumping
 else sprite_index = CalvinJumping
}

and

///Shooting with D
//Shooting direction
if (keyboard_check(vk_right))
{
 mpfacing = 0;
}

if (keyboard_check(vk_left))
{
 mpfacing = 180;
}

if (keyboard_check(vk_up))
{
 mpfacing = 90;
}

//Shooting
if (keyboard_check(ord("D"))) && (canshoot = true)
{
 instance_create(x+13, y-0.5, Obj_MP_Laser);
 canshoot = false;
 alarm[1] = 30;
}

is my code but for some reason when i press up, and move left, i can't jump when i press space. Which i don't understand because i can jump when moving left, and when i press up, but not when i press both.



Related Questions


Changing sprite while jumping

Updated April 18, 2018 02:13 AM


why won't my character move

Updated March 18, 2017 21:13 PM

What is the "logic" of move_towards_point?

Updated March 23, 2017 23:13 PM

Game Maker, my image speed doesn't change

Updated April 15, 2018 00:13 AM