• 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] Check for collision..but only if we're not already colliding

MaxLos

Member
Hihi,

So in my game Mayro is able to do a roll but I don't want you to be able to roll through enemies and stop if you would collide with them, unless your already colliding with them, which in that case roll through them, otherwise you'd just roll in place and that'd be weird lol

This is the collision check I'm currently doing:
Code:
if (place_meeting(x+hsp,y,par_enemy))  
{  
    if !(place_meeting(x,y,par_enemy)) and (sprite_index = spr_Mario_roll) or (sprite_index = spr_Mario_roll_backwards)
    {
        while (!place_meeting(x+sign(hsp),y,par_enemy))
        {
            x = x + sign(hsp); 
        }
        hsp = 0;
    }
}
It works if im not already colliding with an enemy, but if I am and try to roll backwards, the player will roll in place. Doesn't do this when I try to roll foward though. What should I do to fix this? Thanks

 

TheouAegis

Member
...and (sprite_index = spr_Mario_roll) or (sprite_index = spr_Mario_roll_backwards)
Put extra parentheses around these last two.

...and (sprite_index = spr_Mario_roll or sprite_index = spr_Mario_roll_backwards)

Everything in GM is handled as an arithmetic operation, which means you need to properly utilize parentheses to maintain order of operations.
 
Top