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

Trouble with Y collisions

C

crayon_wizard

Guest
Ok, so I've been working on the movement for my character in a platform style game and I added the ability to jump. However, whenever my character is about to land the game freezes. My code for y axis collisions is:

if(place_meeting(x,y+vsp,obj_bound))
{
while(!place_meeting(x,y+sign(vsp),obj_bound))
{
y -= sign(vsp)
}
vsp = 0;
}

I think it must just be I am going into the obj_bound (my boundary/platform) so I tried multiplying sign(vsp) by 0.1 along with a few other things but they didn't seem to help. Ideas?
 

marasovec

Member
That's because you have y -= sign(vsp); instead of y += sign(vsp); so it's going to the opposite direction so loop never ends
Code:
if place_meeting(x, y+vsp, obj_bound)
    {
    while !place_meeting(x, y+sign(vsp), obj_bound)
        {
        y += sign(vsp);
        }
    vsp = 0;
    }
y += vsp;
 

FrostyCat

Redemption Seeker
You are stepping y in the wrong direction inside the while loop. It's +=, not -=.

Since this piece of code is a badly done Spalding copy-and-paste, I suggest that you spend some time actually LISTENING to his explanation of this particular section. Anyone who actually listened should know how senseless the -= is in that position and how that would result in an infinite loop.
 
Top