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
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;