A
Anti-Icarus
Guest
I'm having problems with programming horizontal movement in my prototype game. I've been trying to get my character to move left and right. Simple enough, but for some bizarre reason I can't comprehend, I've been making my character jump when it wasn't supposed to during my latest play tests. Here is the Create event for my character object:
And here is the first part of the Step event where the movement is supposed to be working:
But instead of moving to the right on the D key and to the left on the A key, the character keeps jumping upon pressing one of the two keys even when the space bar is not being pressed. It's like GameMaker is confusing the D key for the Space Bar. I can't identify the bug that's been causing this. Is there a way to fix this bug so that the player character can only move to the right on D, to the left on A, and only jump on the Space Bar?
Code:
/// Initialize variables
global.ice_power = 0;
power_up = 0;
hspeed = 0;
vspeed = 0;
gravity = 10;
gravity_direction = 270;
audio_play_sound(snd_hoverboard, 10, true);
Code:
/// Main controls
//Initialize controls for simplicity
var lm = keyboard_check('a');
var rm = keyboard_check('d');
var jump = keyboard_check('vk_space');
var iceshoot = keyboard_check('s');
var icewave = keyboard_check('w');
//Left and right movements
if (lm) {
hspeed -= 8;
}
if (rm) {
hspeed += 8;
}
//When not moving
if ((!lm && !rm) || (lm && rm))
hspeed = 0;
//Jumping
if (jump) {
gravity = 0;
gravity_direction = 90;
vspeed = 15;
sound_play(snd_jump);
}
else {
if (vspeed < 16) {
vspeed -= 5;
gravity = 0;
gravity_direction = 270;
}
}