GM:S 1.4 Charactor stuck in wall if hitting corner, platformer

Discussion in 'Programming' started by Ssnakee, Jun 2, 2019.

Tags:
  1. Ssnakee

    Ssnakee Member

    Joined:
    Jun 1, 2019
    Posts:
    2
    Alright, so I am working on a platformer game in which you play as a slime and make your way through levels.
    I am using a heavily modified version of Shaun Spalding's code.
    I have many different sprites that I switch between, however I gave them all the same collision box. (Modified).
    I suspect that the issue may be due to how as it is mentioned in the tutorials about centering the origin, and since my character does not take up the entire area and is at the bottom of the 32x32px square perhaps this messes up the collision.
    You only seem to get stuck if you hit the wall at exactly the corner of it.
    However, another problem seems to have arisen is slopes. they work okay with precise collision, but hitting them in the center on an angle causes you to teleport to where you began your jump (Only slopes on roof).

    I will attempt to center the character sprite and return and mark as solved if i fix it.

    I am on Gamemaker:Studio 1.4.9999.
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    Hi and welcome to the GMC!

    You mention using a heavily modified version of some Shaun Spalding's code, but this can only make us guess as to what code you're using exactly.
    Can you please provide all the relevant code for movement and collision in your project?
    Maybe also provide a reference to which code of Shaun Spalding your code is based on.

    Your issue occurs when hitting corners.
    I currently doubt that will be due to how your collision masks and sprites are set up.
     
  3. Hudsonius

    Hudsonius Member

    Joined:
    Aug 13, 2017
    Posts:
    51
    Try using move_contact_solid. You can put in the step event of the player something like:
    Code:
    if place_meeting(x,y,'Your Solid Object')
    {
        move_contact_solid(direction,1)
    }
     
  4. Ssnakee

    Ssnakee Member

    Joined:
    Jun 1, 2019
    Posts:
    2
    Thank you two very much for the replies. To answer the first question, I am using the "Platformer Gamemaker 1.4" turtorial by shaun spaulding. I made many modifications to suit my needs for the game, but this is the basic collision part.

    Code:
    if (place_meeting(x+hsp,y,obj_wall)) && (global.menu = 0)
    {
        while(!place_meeting(x+sign(hsp),y,obj_wall))
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    if (place_meeting(x,y+vsp,obj_wall)) && (global.menu = 0)
    {
        while(!place_meeting(x,y+sign(vsp),obj_wall))
        {
            y += sign(vsp);
        }
        vsp = 0;
    }
    EDIT:
    Don't be thrown off by global.menu, its for my pause menu.

    There is much more going on with other parts, but perhaps this is what was required.
    the vsp at the end is added to y, same with hsp and x.

    I will look into move_contact_solid. Seems interesting!
     
  5. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    What's happening when hitting corner:
    You check for horizontal collision, but because you are about to hit the corner, there is no horizontal collision.
    You check for vertical collision, but for the same reason there is no vertical collision.
    You probably then execute this code:
    Code:
    x += hsp;
    y += vsp;
    Because no collision was detected, neither hsp nor vsp are 0.
    These 2 lines move the player without performing coollision checks, so they move you inside the corner, getting you stuck.

    The solution is simple:
    Move this line:
    Code:
    y += vsp;
    after the horizontal collision check, but in front of the vertical collision check.
     

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