M
mikke
Guest
So I'm SUPER new to GMS2, and all game programming really, so I'm probably making a rookie mistake. I'm following Shaun Spalding's complete platformer tutorial and have copied the code character for character to add movement to the player object, albeit with adjustments for the numbers in his jump/fall animation (it had 6 frames, but I chose 2 of them for the tutorial and my own sake) and variable names. I have the animation for walking set as well, to a speed of 12. However, with this code, I've found that my sprite can't move horizontally unless he's airborne. He can jump horizontally and the animations for jumping work just fine -- if I wanted to make a platformer where the only movement was jumping (before mirroring the sprite) I'd be fine. But on the ground, he's stuck in one spot as his idle sprite. I cannot for the life of me figure it out as I've done the same thing he did, at least as far as I'm aware. I could be having a tunnel vision moment.
I have to be missing something but I can't seem to figure it out, despite putting my GMS2 next to his video to compare the code side-by-side. I found that the problem begins here:
I've double and triple and quadruple and beyond checked with Shaun Spalding's video, it looks the same to me. I could be wrong, however. Any help would be much appreciated!
GML:
// get player input
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up)
//calculate movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,oWall)) and (key_jump)
{
vsp = -7;
}
//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))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
//animation
if (!place_meeting(x,y+1,oWall))
{
sprite_index = sPlayerJump;
image_speed = 0;
if (sign(vsp) > 0) image_index = 2; else image_index = 4;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = sPlayer;
}
else
{
sprite_index = sPlayerWalk;
}
}
GML:
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = sPlayer;
}
}