1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Help with basic platformer.

Discussion in 'Programming' started by Andrew Brown, Feb 6, 2018.

  1. Andrew Brown

    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
     
  2. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    423
    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?
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,434
    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: Feb 6, 2018
  4. Andrew Brown

    Andrew Brown Guest

    no animations yet could that be causing something to happen thats not intended? also negating the left key worked.
     
  5. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    423
    Yes, if your animated sprites aren't aligned you can go inside objects and get stuck like what's happening for 2 and 3.
     
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,434
    I was editing my post. Go back and read my post.
     
  7. Andrew Brown

    Andrew Brown Guest

    ive made multiple changes to it such as that. im still not understanding why when i jump on a platform i get stuck.
     
  8. Andrew Brown

    Andrew Brown Guest

    so do i need a flat sprite? so that the edges don't get caught in the platform?
     
  9. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,434
    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.
     
  10. Andrew Brown

    Andrew Brown Guest

    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?
     

    Attached Files:

  11. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,434
    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.
     
    Bayesian likes this.
  12. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    765
    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.
     
    Bayesian likes this.

Share This Page