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
Collision with Wall_Main:
Wall_Main -
Create Event:
---------------------------------------------------------------------
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
Thankyou in advance,
Beeeej
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
Thankyou in advance,
Beeeej
Last edited by a moderator: