• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Charactor stuck in wall if hitting corner, platformer

S

Ssnakee

Guest
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.
 

jo-thijs

Member
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.
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.
 
H

Hudsonius

Guest
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.
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)
}
 
S

Ssnakee

Guest
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!
 

jo-thijs

Member
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!
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.
 
Top