How to make a character move up and down?

Hello! I am using the code from a skeleton hack n slash game on YouTube as a source and I am trying to figure out how to make the character go up.

Here is the code given:

switch(state)
{
case "move":
#region Move State

if input.up
{
move_and_collide(run_speed, 0);
image_xscale = 2;
sprite_index = s_noir_run;
image_speed = 0.6;
}

if input.down
{
move_and_collide(-run_speed, 0);
image_xscale = -2;
sprite_index = s_noir_run;
image_speed = 0.6;
}

if input.right
{
move_and_collide(run_speed, 0);
image_xscale = 2;
sprite_index = s_noir_run;
image_speed = 0.6;
}

if input.left
{
move_and_collide(-run_speed, 0);
image_xscale = -2;
sprite_index = s_noir_run;
image_speed = 0.6;
}

if !input.left and !input.right and !input.up and !input.down
{
sprite_index = s_noir_idle;
image_speed = 0.6;
}

if input.roll
{
state = "roll";
}

if input.attack
{
state = "attack one";
}
#endregion
break;

case "roll":
#region Rolling
state_set_sprite(s_noir_roll, 0.7, 0);

if image_xscale == 2
{
move_and_collide(roll_speed, 0);
}
if image_xscale == -2
{
move_and_collide(-roll_speed, 0);
}
if animation_end()
{
state = "move";
}
#endregion
break;

case "attack one":
#region Attack One
state_set_sprite(s_noir_attack_one, 0.7, 0);

/*if animation_hit_frame(0)
{
create_hitbox(x, y, self, s_noir_attack_one_damage, 3, 4, 5, image_xscale);
}*/

if input.attack and animation_hit_frame_range(2, 4)
{
state = "attack two";
}


if animation_end()
{
state = "move";
}
#endregion
break;

Once I hit up and down, the character still moves right and left. What to do?

Thanks!
 

Chaser

Member
i see a lot of 'states' for up,down,left,right etc but no 'state' for 'stop' or 'idle', or just a 'state' that the player stops moving, maybe your missing that one.

edit: what is input.up? what function/script is that running? im going to assume that has the horizontal speed/ vertical speed values? perhaps check that out.
 

Simon Gust

Member
I looked up the tutorial on youtube. Pay close attention to part 6, they explain what the script move_and_collide does.
Basically, the first argument in that script controls movement for left and right and the second argument controls the movement for up and down.

What you have to do is adjust the arguments based on input.
Code:
on left input: move_and_collide(-run_speed, 0); 
on up input: move_and_collide(0, -run_speed);
on right input: move_and_collide(run_speed, 0);
on down input: move_and_collide(0, run_speed);
 
Thanks! It worked!
I looked up the tutorial on youtube. Pay close attention to part 6, they explain what the script move_and_collide does.
Basically, the first argument in that script controls movement for left and right and the second argument controls the movement for up and down.

What you have to do is adjust the arguments based on input.
Code:
on left input: move_and_collide(-run_speed, 0);
on up input: move_and_collide(0, -run_speed);
on right input: move_and_collide(run_speed, 0);
on down input: move_and_collide(0, run_speed);
 
Top