Let's make sense of this.

Avyrra

Member
This is more of a call to action than a simple code question as it's a super easy fix, but as I look at this code and find nothing wrong with it, all I can say is "This problem makes no sense!" (At least from what I can see.)

I've been modifying my code that I'm using for a momentum based platformer, based off of the code from Shaun Spalding's platformer tutorial. Trying to make it more streamlined and easier to use. I've settled on the control scheme of using up to jump and C to sprint (because I like it, that's why.) Along with the standard left/right direction arrows.

Anyway, it's super simple and easy to use except for one thing. When I'm sprinting to the right and I press up, I won't jump. But if I'm sprinting left, I can still jump. However, jumping still works both directions with normal walking.

This seemed weird as sprinting and jumping aren't really connected in anyway via code. So I took a look at it, messed around with a few variables and nothing still happened... Until... I changed the sprint button from C to X.

It was at that moment, I thought "wait a minute, wait a minute. What the hell does that do so differently. Is my C key that messed up that it can't interact with the right arrow and up arrow together? Is there some secret keyboard function I don't know about, but might be obvious to everyone else?"

I'm thinking it'd be nice to know what's causing this as I think it might be my new keyboard and I don't want other players with different keyboards to have such a gamebreaking experience should the game be finished. So I'm providing a game file so that people may mess around with it. http://www.mediafire.com/download/s0yxx99kd1devid/momentumplatformer.gmz

And also, here is the movement code
Code:
/// MOVEMENT

//Input
moveLeft = keyboard_check(vk_left);
moveRight = keyboard_check(vk_right);
moveJump = keyboard_check_pressed(vk_up);
moveRun = keyboard_check(ord("C"));


//Check Input
moveDir = moveRight-moveLeft;
targetSpd = moveDir*(baseMoveSpd+runSpd);
if moveSpd<targetSpd {moveSpd += 0.5;}
if moveSpd>targetSpd {moveSpd -= 0.5;}
runSpd = moveRun*baseRunSpd;
hspd = moveSpd;

if (vspd<10) {vspd += grav;}
if place_meeting(x,y+1,obj_collision)
{
    vspd = moveJump * -baseJumpSpd;
}

//Output
if (place_meeting(x+hspd,y,obj_collision))
{
    while(!place_meeting(x+sign(hspd),y,obj_collision))
    {
        x += sign(hspd);
    }
    hspd = 0;
    moveSpd = 0;
}
x += hspd;

if (place_meeting(x,y+vspd,obj_collision))
{
    while(!place_meeting(x,y+sign(vspd),obj_collision))
    {
        y += sign(vspd);
    }
    vspd = 0;
}
y += vspd;
 

jo-thijs

Member
Sounds like it is a combination your keyboard doesn't recognize.
My keyboard does recognize it however and I can run your game just fine (with X changed to C).
Other keyboard combinations like left+up+space are not recognized by my keyboard.

The shift key should be a pretty safe bet as run button.
It should work on all keyboards in combination with any arrow key combination AFAIK.
 
S

StuffandThings85

Guest
some keyboards may not recognize multiple presses for some reason. I had a hard time playing I Wanna Be the Guy: Gaiden (jumping while using the hook thing), and when I changed keyboards it became much easier.
 

Avyrra

Member
Interesting.
As a further update, I tested all buttons on my keyboard. Turns out I can't do the keybinds in general (even when the button tested isn't bound to sprint.)
These are the following keys I found do not work with Right/Up arrow combo on my keyboards.
0 = T I O A S D F G H ; ' C V B N

Testing includes backspace, enter, ctrl, etc


Edit: Oddly enough, the only button that doesn't work with jumping and moving left is ;
 
Last edited:

kburkhart84

Firehammer Games
The best solution for keyboard ghosting(as many target audiences won't have gaming keyboards) is to allow customizing of the game inputs. Let the player choose what button they want to use to jump with, sprint with, etc... Though they might not want to invest in a gaming keyboard, they may well know/recognize the ghosting problem, and have good general inputs they like to use, like maybe instead of WASD, scoot over and use ESDF, if for some reason this works without ghosting on their particular keyboard. It also is simply a feature many gamers expect, regardless of whether they have a gaming keyboard, and it should allow them to use gamepads as well, customizing the inputs for those too.
 
Top