GameMaker [SOLVED] My player character can not jump, move sideways and shoot at the same time.

A

AtomicBlade

Guest
As the title suggests, my player character can't shoot if you hold space and move sideways in the air. They also can't move sideways if space is held while shooting in the air as well as being unable to jump if they are moving sideways and shooting. It's very odd and I can't find any code that directly relates them all together. Here's the step (involved in movement and jumping) and begin step (involved with shooting) events. I'm sorry if it's too much, but I really don't know what is effecting each other.

Step event:

//Get_Player Input

if (hascontrol = true)

{

key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));

key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));

//key_jump = keyboard_check_pressed(vk_space) || keyboard_check_pressed(ord("W"));

}

else

{

key_right = 0;

key_left = 0;

key_jump = 0;

}


key_jump = keyboard_check_pressed(vk_space)


//Calculate Movement

var move = key_right - key_left;


hsp = move * walksp;


vsp = vsp + grv;


//Jumping

if (canjump > 0) && (key_jump)

{

vsp = -11;

canjump = 0;



}


//Horizontal Collision

if (place_meeting(x+hsp,y,oWall))

{

while (!place_meeting(x+sign(hsp),y,oWall))

{

x = x + sign(hsp);

}

hsp = 0;

}

x = x + hsp;


//Vertical Collision

if (place_meeting(x,y+vsp,oWall)) || (place_meeting(x,y+vsp,oPlatform))

{

while (!place_meeting(x,y+sign(vsp),oWall)) && (!place_meeting(x,y+sign(vsp),oPlatform))

{

y = y + sign(vsp);

}

vsp = 0;

}

y = y + vsp;


// Weapon Use


if (keyboard_check(ord("E"))) && (GunSwitchTimeout = 0) {

WeaponOut = !WeaponOut;

GunSwitchTimeout = 10;

}

if (GunSwitchTimeout > 0) GunSwitchTimeout -= 1;


//Animation

if (!place_meeting(x,y+1,oWall)) && (!place_meeting(x,y+1,oPlatform))

{

if (WeaponOut = false) sprite_index = sSwatPFalling;

else if (WeaponOut) sprite_index = sSwatPFallingGun;

image_speed = 0;

if (sign(vsp) > 0) image_index = 1; else image_index = 0;

canjump = canjump - 1;

}

else

{

canjump = 10;


image_speed = 1;

if (hsp == 0)

{

if (WeaponOut = false) sprite_index = sSwatP;

else if (WeaponOut) sprite_index = sSwatPGun;

}

else

{

if (WeaponOut = false) sprite_index = sSwatPWalk;

else if (WeaponOut) sprite_index = sSwatPWalkGun;

}

}


if (hsp != 0) image_xscale = sign(hsp);


with (oPlatform)

{

if (round(other.y + ((other.sprite_height/2)-16)) > y || keyboard_check_pressed(vk_down)) || keyboard_check_pressed(ord("S"))

{

mask_index = -1;

}

else

{

mask_index = sPlatform;

}

}


// Invinsiblity Frames


if (iFrames > 0) iFrames -= 1;


//Health System


if (!instance_exists(oHeart3)) && (hp = 3) {

instance_create_depth(x+25,y-40,0,oHeart3);

with (oHeart3) {

sprite_index = sHeartHeal;

image_speed = 1;

image_index = 0;

}

}


if (!instance_exists(oHeart2)) && (hp >= 2) {

instance_create_depth(x-25,y-40,0,oHeart2);

with (oHeart2) {

sprite_index = sHeartHeal;

image_speed = 1;

image_index = 0;

}

}

if (keyboard_check(ord("H"))) hp = 3;


//Directional Shooting


if (keyboard_check(ord("A"))) {dir_left = true}

else dir_left = false;

if (keyboard_check(ord("D"))) {dir_right = true}

else dir_right = false;

if (keyboard_check(ord("W"))) {dir_up = true}

else dir_up = false;

if (keyboard_check(ord("S"))) {dir_down = true}

else dir_down = false;


if (dir_left) {

image_xscale = -1;

bullet_facing = 180;

}


if (dir_right) {

image_xscale = 1;

bullet_facing = 0;

}


if (dir_up) {

bullet_facing = 90;

}


if (dir_down) {

bullet_facing = 270;

}


if (dir_up) && (dir_right) {

image_xscale = 1;

bullet_facing = 45;

}


if (dir_up) && (dir_left) {

image_xscale = -1;

bullet_facing = 135;

}


if (dir_down) && (dir_right) {

image_xscale = 1;

bullet_facing = 315;

}


if (dir_down) && (dir_left) {

image_xscale = -1;

bullet_facing = 225;

}


if(keyboard_check(vk_shift)) {

hascontrol = false;



}else hascontrol = true;


Begin Step Event:

if (WeaponOut) {

if (keyboard_check(vk_enter)) && (firingdelay = 0)

{

firingdelay = 10;

screenShake(2,25);

repeat(bullets) with(instance_create_layer(x,y-15,"Instances",oSpunk))

{

spd = 25;

direction = other.bullet_facing + random_range(-3*other.bullets,3*other.bullets);

image_angle = direction;

}

}

}

if (specialdelay > 0) specialdelay = specialdelay - 1;


// Special Use

if (WeaponOut = false) {

if (keyboard_check(ord("Q"))) && (specialdelay = 0)

{

specialdelay = fps*60;

screenShake(2,25);

repeat(specialBullets) with(instance_create_layer(x,y-15,"Instances",oSpecialSpunk))

{

spd = 25;

direction = other.bullet_facing + random_range(-3*other.specialBullets,3*other.specialBullets);

image_angle = direction;

}

}

}
 

CloseRange

Member
One thing I've learned on this forums is that if you don't keep your code in code blocks and organized people are much less likely to help you, so for anyone else in the future here you go:
Code:
//Get_Player Input

if (hascontrol = true) {
    key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
    key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
    //key_jump = keyboard_check_pressed(vk_space) || keyboard_check_pressed(ord("W"));
} else {
    key_right = 0;
    key_left = 0;
    key_jump = 0;
}
key_jump = keyboard_check_pressed(vk_space)

//Calculate Movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
//Jumping
if (canjump > 0) && (key_jump) {
    vsp = -11;
    canjump = 0;
}

//Horizontal Collision
if (place_meeting(x+hsp,y,oWall)) {
    while (!place_meeting(x+sign(hsp),y,oWall)) {
        x = x + sign(hsp);
    }
    hsp = 0;
}
x = x + hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,oWall)) || (place_meeting(x,y+vsp,oPlatform)) {
    while (!place_meeting(x,y+sign(vsp),oWall)) && (!place_meeting(x,y+sign(vsp),oPlatform)) {
        y = y + sign(vsp);
    }
    vsp = 0;
}
y = y + vsp;

// Weapon Use
if (keyboard_check(ord("E"))) && (GunSwitchTimeout = 0) {
    WeaponOut = !WeaponOut;
    GunSwitchTimeout = 10;
}
if (GunSwitchTimeout > 0) GunSwitchTimeout -= 1;

//Animation
if (!place_meeting(x,y+1,oWall)) && (!place_meeting(x,y+1,oPlatform)) {
    if (WeaponOut = false) sprite_index = sSwatPFalling;
    else if (WeaponOut) sprite_index = sSwatPFallingGun;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1;
    else image_index = 0;
    canjump = canjump - 1;
} else {
    canjump = 10;
    image_speed = 1;
    if (hsp == 0) {
        if (WeaponOut = false) sprite_index = sSwatP;
        else if (WeaponOut) sprite_index = sSwatPGun;
    } else {
        if (WeaponOut = false) sprite_index = sSwatPWalk;
        else if (WeaponOut) sprite_index = sSwatPWalkGun;
    }
}
if (hsp != 0) image_xscale = sign(hsp);
with (oPlatform) {
    if (round(other.y + ((other.sprite_height/2)-16)) > y || keyboard_check_pressed(vk_down)) || keyboard_check_pressed(ord("S")) {
    mask_index = -1;
    } else {
        mask_index = sPlatform;
    }
}

// Invinsiblity Frames
if (iFrames > 0) iFrames -= 1;
//Health System
if (!instance_exists(oHeart3)) && (hp = 3) {
    instance_create_depth(x+25,y-40,0,oHeart3);
    with (oHeart3) {
        sprite_index = sHeartHeal;
        image_speed = 1;
        image_index = 0;
    }
}
if (!instance_exists(oHeart2)) && (hp >= 2) {
    instance_create_depth(x-25,y-40,0,oHeart2);
    with (oHeart2) {
        sprite_index = sHeartHeal;
        image_speed = 1;
        image_index = 0;
    }
}
if (keyboard_check(ord("H"))) hp = 3;

//Directional Shooting
if (keyboard_check(ord("A"))) {dir_left = true}
else dir_left = false;
if (keyboard_check(ord("D"))) {dir_right = true}
else dir_right = false;
if (keyboard_check(ord("W"))) {dir_up = true}
else dir_up = false;
if (keyboard_check(ord("S"))) {dir_down = true}
else dir_down = false;

if (dir_left) {
    image_xscale = -1;
    bullet_facing = 180;
}
if (dir_right) {
    image_xscale = 1;
    bullet_facing = 0;
}
if (dir_up) {
    bullet_facing = 90;
}
if (dir_down) {
    bullet_facing = 270;
}
if (dir_up) && (dir_right) {
    image_xscale = 1;
    bullet_facing = 45;
}
if (dir_up) && (dir_left) {
    image_xscale = -1;
    bullet_facing = 135;
}
if (dir_down) && (dir_right) {
    image_xscale = 1;
    bullet_facing = 315;
}
if (dir_down) && (dir_left) {
    image_xscale = -1;
    bullet_facing = 225;
}
if(keyboard_check(vk_shift)) {
    hascontrol = false;
} else hascontrol = true;




// ------- Begin Step Event:

if (WeaponOut) {
        if (keyboard_check(vk_enter)) && (firingdelay = 0) {
        firingdelay = 10;
        screenShake(2,25);
        repeat(bullets) with(instance_create_layer(x,y-15,"Instances",oSpunk)) {
            spd = 25;
            direction = other.bullet_facing + random_range(-3*other.bullets,3*other.bullets);
            image_angle = direction;
        }
    }
}
if (specialdelay > 0) specialdelay = specialdelay - 1;

// Special Use
if (WeaponOut = false) {
    if (keyboard_check(ord("Q"))) && (specialdelay = 0) {
        specialdelay = fps*60;
        screenShake(2,25);
        repeat(specialBullets) with(instance_create_layer(x,y-15,"Instances",oSpecialSpunk)) {
            spd = 25;
            direction = other.bullet_facing + random_range(-3*other.specialBullets,3*other.specialBullets);
            image_angle = direction;
        }
    }
}
One thing I noticed in the begin step event is you have a variable called firingdelay. You can only shoot if it's 0 and you set it to 10 when you shoot.
I searched and nowhere in the code you showed do you decrement it back down to 0 so where are you holding that code?
 
A

AtomicBlade

Guest
Hi, thanks for the reply and advice. The firing delay variable shouldn’t be a problem, I don’t have my computer to actually check right now, but it fires correctly at all other times. When I look again, I’ll see if firing delay has anything to do with it. Is there anything else that jumps out to you?
 
This isn't a code or GameMaker issue, it comes down to keyboard ghosting. In short, don't use the arrow keys and the space bar as a control scheme.
 
A

AtomicBlade

Guest
This isn't a code or GameMaker issue, it comes down to keyboard ghosting. In short, don't use the arrow keys and the space bar as a control scheme.
What would I need to do to fix it? I’m not very familiar with coding and have only recently come back from a long break.
 
A

AtomicBlade

Guest
That makes sense. I hope it isn’t such a big issue that I need to redo keybindings. Hopefully it only effects me due to my terrible laptop.
 
It's a bigger issue than you may realize. Some crappy keyboards may be affected, and even some nice ones. It's all up to how they're designed. It's generally recommended to just avoid using the space bar if you're going to be using the arrow keys.
 

TheouAegis

Member
Make the controls 100% customizable. This ain't for a normal game console, so there's no reason to hard-code the keys. Use variables instead of key codes and allow the player to specify what key codes to save in each variable.
 
Top