# Platformer collision problems :| Help?

B

#### Beeeej

##### Guest
So i'm currently in the middle of developing a simple 2D platformer and am having collision troubles when it comes to the Player falling onto a platform.

The game is designed to be featured in only one screen-sized room with the Player in the center and the 64x64 blocks that make up the various different sized platforms move on to the screen from the right side and travel to the left side, with the Player having to navigate over them without being dragged off-screen with them.

The collisions regarding the Player landing on, jumping off and being unable to jump if there is a block above them are all fine, but when it comes to the Player falling, just as a platform is moving across the screen and colliding from the right side, there seems to be some sort of glitch where the Player jumps below the block (off from it's y axis) and continues falling off screen.

Below is the code i am using for, both, the Player and the blocks that make up the Platforms ("Wall_Main")..

(Bear in mind I am still an amateur with GML coding)

---------------------------------------------------------------------
Obj Player -

Step Event:

///Movement

Code:
``````gravity_direction = 270

//Check if behind block - Drag backwards
if !(place_free(x+(global.levelspeed),y))
{x -= (global.levelspeed);}

//Check if on ground -
if (place_free(x,y+1))
{
gravity = 1
//Falling?
if vspeed>0
{
sprite_index=Fall;
if (place_meeting(x+(global.levelspeed),y,Wall_Main))
{
move_outside_solid(0,5);
}
}
}
else
{
gravity = 0
//On ground - Want to jump?(Action - Mouse Press)
if mouse_check_button_pressed(mb_left) && !place_free(x,y+1)
{
sprite_index=Jump;
vspeed = -20
}
}``````

Collision with Wall_Main:

Code:
``````///Check when falling

if vspeed > 0 && !place_free(x,y+vspeed)
{
sprite_index=Walk_Right;
move_contact(270)
}
//Sets vspeed back to 0
vspeed = 0``````

Wall_Main -

Create Event:

Code:
``````//Move toward left of screen

move_towards_point(-70,y,global.levelspeed);``````
---------------------------------------------------------------------

The Player Object is masked by a 64x64 square with it's origin at the centre, whereas the Wall_Main Object uses it's own sprite (square) with no specified origin (0x0). Any attempt to use the same mask with both Objects just throws the entire setup all out of whack resulting in major collision issues with everything.

Any help would be very much appreciated as I am still learning

Beeeej

Last edited by a moderator:

#### jazzzar

##### Member
as i always tell people, tag your code and i will help, i can't bother reading it like that

B

#### Beeeej

##### Guest
as i always tell people, tag your code and i will help, i can't bother reading it like that
Ahh yes. Updated

M

#### Me Myself and I

##### Guest
Sorry, but your description is a bit confusing -- you're saying that when your player "falls" onto a moving platform, they don't stop? They just keep on falling through the bottom of the screen?

B

#### Beeeej

##### Guest
Falling on to a moving platform is usually fine.
It is when a platform collides with the Player from the right side as he is falling.

M

#### Me Myself and I

##### Guest
Thanks for clarifying.

You define "falling" as vspeed > 0. If the player continues falling after colliding with the platform, then vspeed is NOT being set to zero. and gravity stays on. You can try setting vspeed and/or gravity on that collision event/check.

That said, I think the problem is here:
if (place_meeting(x+(global.levelspeed),y,Wall_Main))
{
move_outside_solid(0,5);
}

You're saying, "if there is a collision to the right of the player, keep moving the player to the right, 5 pixels at a time, until the player is out of that collision"....that suggests to me that the player is passing through the platform and continuing to "fall" as before. Maybe try moving up out of the collision? IE: move_outside_solid(90,5). That way they would land on it as though it were the ground and stop falling.

B

#### Beeeej

##### Guest
Thanks for clarifying.

You define "falling" as vspeed > 0. If the player continues falling after colliding with the platform, then vspeed is NOT being set to zero. and gravity stays on. You can try setting vspeed and/or gravity on that collision event/check.

That said, I think the problem is here:
if (place_meeting(x+(global.levelspeed),y,Wall_Main))
{
move_outside_solid(0,5);
}

You're saying, "if there is a collision to the right of the player, keep moving the player to the right, 5 pixels at a time, until the player is out of that collision"....that suggests to me that the player is passing through the platform and continuing to "fall" as before. Maybe try moving up out of the collision? IE: move_outside_solid(90,5). That way they would land on it as though it were the ground and stop falling.
I've solved the problem!
While it was not exactly that bit of code that was causing the issue it did give me a different perspective and better insight into the "moving_outside..etc" functionality.
The culprit seemed to be the 'move_contact_solid(270)' upon the collision with Wall event.