Help with basic platformer.

A

Andrew Brown

Guest
I'm making a platformer for a school project and my basic code has come back with multiple problems when playing the game. 1. my left key makes me move right, but i want it to move left. 2. jumping and hitting a platform with the top of the player makes the player stuck on the platform. 3. After jumping the player can no longer move. Any help is appreciated. Here is the code.code 2.png code 1.png
 

Bayesian

Member
To fix #1 do this instead:
Code:
key_left = -keyboard_check(vk_left);
As for #2 and 3 I don't see what's causing this, your code is fine. Are you doing any animations?
 

TheouAegis

Member
You forgot to negate your left key.

Your jumpspeed is negative and you set your vsp to -jumpspeed, so you move down when you jump... I don't get how you are even moving up.

You use if place_meeting(x,y+sign(vsp), obj_platform). It should be of place_meeting(x,y+vsp,obj_platform).
 
Last edited:
A

Andrew Brown

Guest
To fix #1 do this instead:
Code:
key_left = -keyboard_check(vk_left);
As for #2 and 3 I don't see what's causing this, your code is fine. Are you doing any animations?
no animations yet could that be causing something to happen thats not intended? also negating the left key worked.
 
A

Andrew Brown

Guest
You forgot to negate your left key.

Your jumpspeed is negative and you set your vsp to -jumpspeed, so you move down when you jump... I don't get how you are even moving up.

You use if place_meeting(x,y+sign(vsp), obj_platform). It should be of place_meeting(x,y+vsp,obj_platform).
ive made multiple changes to it such as that. im still not understanding why when i jump on a platform i get stuck.
 
A

Andrew Brown

Guest
Yes, if your animated sprites aren't aligned you can go inside objects and get stuck like what's happening for 2 and 3.
so do i need a flat sprite? so that the edges don't get caught in the platform?
 

TheouAegis

Member
Did you change that line of code that I pointed out? Post your your new vertical collision code again so I can make sure you did it right.
 
A

Andrew Brown

Guest
Did you change that line of code that I pointed out? Post your your new vertical collision code again so I can make sure you did it right.
im no longer hitting getting stuck on the platforms. I don't understand what the difference between sign(vsp), and just vsp is, and why one causes you to stick to the platforms?
 

Attachments

TheouAegis

Member
Well to be frank, your first code never worked to begin with. It didn't do anything at all. If there is a collision one pixel above you, then there can't NOT be a collision one pixel above you. So all it does is move into the wall until it is in the wall and then prevents you from moving anymore.
 

Rob

Member
im no longer hitting getting stuck on the platforms. I don't understand what the difference between sign(vsp), and just vsp is, and why one causes you to stick to the platforms?
if you followed Shaun Spaulding's platformer tutorial, he explains that the sign of vsp will return either -1, 0 or 1. Returning -1 or 1 lets your game know whether the player is moving left (-1) or right (1).

I only mention Shaun because I was checking out his platformer tutorial today and your code is the same.

If the player is getting stuck then the collision check isn't working as intended. You want to check for a future collision, so whatever direction the player is moving in, plus the players speed and if there's a wall there then only allow the player to move up to the coordinates before the object.
 
Top