Wibratorus
Member
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]
[Steps]
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;
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