• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

I've made a programming mess.

Allright, long story short - I don't know how to move up and down using the code I created. (I can move right and left just fine)
I'm very new to programming and I can't continue my project without overcoming this.

My code is -
[Create]
GML:
//speeds

hsp = 0;

vsp = 0;

max_hsp = 3;

max_vsp = 10;

grav = 0.4;


//player inputs

key_left = 0;

key_right = 0;

key_up = 0;

key_down = 0;


//momentum

accel = 0.5;

decel = 0.3;
[Steps]
Code:
key_left = keyboard_check(vk_left);

key_right = keyboard_check(vk_right);

key_up = keyboard_check(vk_up);

key_down = keyboard_check(vk_down);



var dir = key_right - key_left;


hsp += dir * accel;


if (dir == 0) //slow down character if no key is pressed

{

    if (hsp < 0) //going left

    {

        hsp = min(0,hsp+decel) //if player is still going left

    }

    else //going right

    {

        hsp = max(0,hsp-decel) //if player is still going right

    }

}


hsp = clamp(hsp,-max_hsp,max_hsp);


x += hsp; //move the character
 

Ommn

Member
step event:
GML:
key_left = keyboard_check(vk_left);

key_right = keyboard_check(vk_right);

key_up = keyboard_check(vk_up);

key_down = keyboard_check(vk_down);



var dir = key_right - key_left;
var dirV = key_down - key_up;

hsp += dir * accel;
vsp += dirV * accel;

if (dir == 0) //slow down character if no key is pressed

{

    if (hsp < 0) //going left

    {

        hsp = min(0,hsp+decel) //if player is still going left

    }

    else //going right

    {

        hsp = max(0,hsp-decel) //if player is still going right

    }

}

if (dirV == 0) //slow down character if no key is pressed

{

    if (vsp < 0) //going left

    {

        vsp = min(0,vsp+decel) //if player is still going left

    }

    else //going right

    {

        vsp = max(0,vsp-decel) //if player is still going right

    }

}


hsp = clamp(hsp,-max_hsp,max_hsp);
vsp = clamp(vsp,-max_vsp,max_vsp);

x += hsp; //move the character
y += vsp; //move the character
 
For some reason while moving up or down my character is suuuper fast, but since it works I'm very happy anyway!!

EDIT - Okay, figured it out, I'm dumb!
 
Last edited:
Top