Windows Platformer tutorial - player won't move!

babydoll

Member
Hi, I thought I would get a quicker response posting here than on the youtube video for the Complete Platformer Tutorial part 1.

I completed the my first game tutorial and managed to iron out every little glitch I game across as I went along... but this one I cannot figure out the problem

It was working fine as we coded the left and right movement, and my player was moving fine. Then we added the horizontal collision and she hasn't moved since. She has a lovely walking animation (that I'm yet to learn how to assign to movements etc!) but keyboard left and right don't move her. I decided to finish the tutorial and have double checked all the code is in correct. She won't move or jump, at all. No matter what key I press. and I cannot for the life of me figure out what I've done wrong. Here is my step code:

//Get Player Input
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);

//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,obj_wall)) && (key_jump)
{
vsp = -7;
}

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

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

babydoll

Member
no there is a new line after "collision" and before "if" I think I just accidentally backspaced it when I pasted as I was trying to tidy up the line breaks.

If I take out everything except the top movement lines she moves left and right fine, I tried putting in the jump part and that had some success but not as nicely as I'd hoped.... or she doesn't move at all, but the collisions they either don't work at all, she doesn't move, or they mess up the game and crash it.

I'm actually though wanting to amend the code so that the character can move all 4 directions (left, right, up and down) and ditch the jump altogether, but I still need the wall collision to work. Any advice and help greatly appreciated. I could use the simpler code for the movement that was on the My First Game tutorial but I would have no idea how to relate that to the collision code (that is currently not working). Happy to take either approach as long as I can get it working.
 

Nidoking

Member
There may be an issue with you not setting the gravity to 0 when you're standing on the ground. It looks like it should still work, but maybe that's affecting something somewhere else.
 
Top