# Legacy GM[SOLVED]Diagonal Jump

C

#### ChrisMG12

##### Guest
I'm making a fighting game with movement physics which is the same as Shaun Spalding's Platformer video
Create Event
grav = 1.5;
hsp = 0;
vsp = 0;
jumpspeed = 20;
movespeed = 4;
last_dir = 1
inv=false
dir=1
jumps=0
jumpsmax=1

Step Event:
///Input

//React to Inputs
move = key_left+key_right;

hsp = 2*move*movespeed;

if (vsp < 10) vsp+= grav;

if (place_meeting(x,y+1,obj_floor))
{
jumps=jumpsmax
}
if (key_jump) && (jumps>0)
{
jumps-=1
vsp = key_jump * -jumpspeed
}
if (vsp<0)&& (!key_jump_held) vsp=max(vsp,-jumpspeed/4)
if not place_meeting(x,y+vsp,obj_floor) && ((key_right)||(key_left)){hsp=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;

I kept that last bit before the Horizontal collision to stop the character from moving while in the air, However, I want to keep that diagonal jump in most Fighting games like SF where you can only do a diagonal jump by pressing both the up and left/right button at the same time. Is there anything I can add to the code to make it possible to do that kind of jump, while still making sure I can't move any other way in the air.

#### 3dgeminis

##### Member
I leave marked the changes I made:

Code:
``````///Input
key_right=keyboard_check(vk_right)
key_left=-keyboard_check(vk_left)
key_jump=keyboard_check_pressed(vk_up)
key_jump_held=keyboard_check(vk_up)

//React to Inputs
if vsp=0 {move = key_left+key_right}; ///CHANGE //////////////////////////

hsp = 2*move*movespeed;

if (vsp < 10) {vsp+= grav};

if (place_meeting(x,y+1,obj_floor)) {jumps=jumpsmax}
if (key_jump) && (jumps>0)
{
j_move=move ///CHANGE (j_move new variable)//////////////////////////
jumps-=1
vsp = key_jump * -jumpspeed
}
if (vsp<0)&& (!key_jump_held) {vsp=max(vsp,-jumpspeed/4)};
///if not place_meeting(x,y+vsp,obj_floor) && ((key_right)||(key_left)){hsp=0} ///CHANGE (deleted)///////

if vsp=0 {hsp=j_move*movespeed} ///CHANGE //////////////////////////

//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
if vsp<0 {j_move=0} ////CHANGE //////////////////////////
}
y +=vsp;``````

C

#### ChrisMG12

##### Guest
Thanks, it worked. Thank u so much, this was bugging me forever