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

Problems with Player colliding with more than one block.

conman06

Member
Ok, so I know that when the Player collides with oWall, it works. But, when I try to collide with oBlock, it does not work. My game just freezes up and I have to end task. :( very disappointing
Here is the code for oPlayer (player) in Step: (btw vsp stands for vertical speed)
Code:
//Vertical Collision
if (place_meeting(x,y+vsp,oWall)) || (place_meeting(x,y+vsp,oBlock))
{
    while (!place_meeting(x,y+sign(vsp),oWall)) || (!place_meeting(x,y+sign(vsp),oBlock))
    {
        y = y + sign(vsp) *  2;
    }
    vsp = 0;
}
y = y + vsp;
Here's a video for clarification: https://gyazo.com/68e5add3d7a815f9d53d92a78685b3f0 also I'm pretty new, just a heads up,
 

Simon Gust

Member
When stacking negated if-statements you have to use && instead of ||, otherwise your while-statement runs into an infinite loop.

Or put simply, make a parent object for oWall and oBlock and then check for the parent only.
1589090856636.png
 

Yal

šŸ§ *penguin noises*
GMC Elder
while (!place_meeting(x,y+sign(vsp),oWall)) || (!place_meeting(x,y+sign(vsp),oBlock))
"while there's no wall in the way, or no block in the way" means "do this until there's both a wall and a block in the way", which is why you're experiencing the freezes.

In general, it's a good idea do design your loops so that they will always end eventually, sometimes you can have edge cases that will cause infinite loops that only happens sometimes (e.g. because of bugs in collision checking so a large movement has a collision and a small doesn't), and it's really hard to figure out what causes those crashes. Fun fact: your code will also have an infinite loop if you ever get inside a block/wall with 0 vertical speed, since adding sign(0) = 0 to your position won't ever move you out of the collision.
 
Top