1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Jump gets cut short when player is up against a wall

Discussion in 'Programming' started by jchuy, Aug 12, 2019.

  1. jchuy

    jchuy Member

    Joined:
    Mar 9, 2019
    Posts:
    2
    Hello,

    I'm running into an issue with jumping when my player is up against the wall. It will cut the jump short at the first frame after rising 10 pixels (the value of the vsp when jumping). This is where it peaks before gravity starts pulling it down:
    ss.png
    The next frame has the on_ground variable being set to true. I'm guessing it has something to do with the collision code?

    I have some standard collision code set up in a script:
    Code:
    // Horizontal Collision
    if (place_meeting(x+hsp,y,o_wall))
    {
        while (!place_meeting(x+sign(hsp),y,o_wall))
        {
            x = x + sign(hsp);
        }
        hsp = 0;
    }
    
    //vertical collision
    if place_meeting(x,y+vsp,o_wall)
    {
        while (!place_meeting(x,y+sign(vsp),o_wall))
        {
            y = y + sign(vsp);
        }
        vsp = 0;
        on_ground = true;
    
    } else
    {
        on_ground = false;
    }
    If it's relevant, I'm using a state machine in scripts to switch between idle, jumping, and walking states. Any ideas on what could be causing the jump to be cut short? I'm pretty new to this so let me know if there's something I can provide that can give more context. Any help is appreciated!

    EDIT: If jumping towards the wall, the player will get hsp set to 0 before coming in contact with it, as if colliding. Upon landing and moving right, the player becomes flush with the wall as usual. I feel like this is probably related to the above. This is where this occurs:
    ss2.png
     
    Last edited: Aug 12, 2019
  2. 3dgeminis

    3dgeminis Member

    Joined:
    Jun 21, 2016
    Posts:
    120
    I don't see anything wrong.
    Without the full code, it's hard to know where the problem is.
     
  3. Amon

    Amon Member

    Joined:
    Sep 13, 2016
    Posts:
    229
    If you have several sprites that form the player object make sure the collision mask is not interfering with the jump anim due to it being a different size. Check your collision mask and make sure it is the same for each sprite that forms your player object.
     
  4. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    This might not be connected to your problem but...

    If there's a vertical collision, you set "on_ground" to true. What if the vertical collision is with something above you? The "else" will set "on_ground" to false the next frame, but if you have checks that rely on on_ground after that code in the current frame, or before that code in the next frame, on_ground will be true when you are in the air.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice