• 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 [SOLVED] Platformer movement/collision bug

D

Dashiello

Guest
[edit] Turns out I checked the 'precise collisions' checkbox on every sprite I made and that was causing some issues. I unchecked most of them and now it works fine!

Hello! This is my first post!
So I'm making a game, and it's going so much better than any other game I've tried to make. Unfortunately, I found a bug that I am unable to fix or really understand.
I was using a modified version of Shaun Spalding's platformer code that allows you to move up and down slopes. However, I tried to change my code so your characters movement had acceleration, and I ran into some bugs.
The bug is very specific, so it'll take some explaining. When standing up against the right of a collision object and jumping, then quickly turning right, the code registers a collision detection. This only happens when you are on the right of a vertical wall, it does not happen when you are on the right. Before, if you turned right it would teleport as far right as was open. I think it has something to do with collision detection being based on your hsp but I really have no idea.
Anyone have any idea what's going on with this? If anyone knows a better way to do movement with acceleration, that would be handy. Thanks!

Movement Code:
Code:
move = (key_left + key_right);
//direction
if (move!=0) playerdirection = move;
image_xscale = playerdirection;

//
hsp=clamp(hsp,-global.movespeed,global.movespeed);
hsp += move * global.movespeed/9;
if (move=0)
{
    hsp -= sign(hsp)/2;
    if(abs(hsp) < 1) hsp=0;
}

if (vsp < fallspeed) vsp += grav;

if (place_meeting(x,y+1,obj_collision))
{
   vsp = key_jump * -global.jumpspeed;
}
if (vsp < 0) && (!key_jump_held) vsp*=0.91;
Collision Code:
Code:
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_collision))
{
    yplus = 0;
    while (place_meeting(x+hsp,y-yplus,obj_collision_angle) && yplus <= abs(slopetolerence*hsp)) yplus += 1;
    if place_meeting(x+hsp,y-yplus,obj_collision)
    {
        while(!place_meeting(x+sign(hsp),y,obj_collision))
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    {
        y-=yplus;
    }
}
else if(!jumping)
{
    yplus = abs(slopetolerence*hsp);
    while(place_meeting(x+hsp,y+yplus,obj_collision_angle)) && (yplus >0) yplus -=1;
    if(!place_meeting(x+hsp,y+yplus,obj_collision))
    {
        if (place_meeting(x+hsp,y+yplus+1,obj_collision))
        {
              y+=yplus;
        }
    }
}
x += hsp;
 
//Vertical Collision
if (place_meeting(x,y+vsp,obj_collision))
{
    while(!place_meeting(x,y+sign(vsp),obj_collision))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;
 
Last edited by a moderator:
Q

QuackProductionz

Guest
Strange bug I've noticed his platform code has many issues like this I also making a platformer I'd recommend splitting code up like two code blocks maybe three use one for movement then one other for collision heck put the collision code into a collision event and shorten the code I have had issues also mainly character will phase through objects when falling too fast also using his code so probly best to redo the code from scratch even sounds drastic I know
 
Q

QuackProductionz

Guest
Also probably best to name you variables in full and don't use collision to name a object could cause typos down the road best call your collision obj solid or even wall
 
D

Dashiello

Guest
Strange bug I've noticed his platform code has many issues like this I also making a platformer I'd recommend splitting code up like two code blocks maybe three use one for movement then one other for collision heck put the collision code into a collision event and shorten the code I have had issues also mainly character will phase through objects when falling too fast also using his code so probly best to redo the code from scratch even sounds drastic I know
I put the collisions and the movement in separate scripts so I can call them at different times if need be. I don't know anymore if it's actually the collision object causing the problems or if it's something else...
Anyway, thanks for the suggestion! Good luck on your game!
 
Q

QuackProductionz

Guest
I put the collisions and the movement in separate scripts so I can call them at different times if need be. I don't know anymore if it's actually the collision object causing the problems or if it's something else...
Anyway, thanks for the suggestion! Good luck on your game!
I say probably best to look at heartbeast tuts for platformers his code is very similar except he goes more in depth and i could have sworn he does exactly what you are trying to do with slopes i cant link his page here because i just recently made an account But Youtube HeartBeast or realTutsGML i think thats how he spells it good luck to you also
 
Top