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

Windows Collision works only once!

P

PPowerrr

Guest
Hey everyone,
I am trying to learn Gamemaker Studio 2 and I gave myself the task to make a 2player game of tag.
I now have 2 players, who can walk around and bump into walls. I also started on the tagging but I came across a problem.
For tagged and not tagged I use a variable
GML:
tagged = 1;
or
GML:
tagged = 0;
where 1 means you are the tagger and 0 means you're not.

So this is the code I use for tagging:
GML:
//tagging
if (collision_rectangle(x-0.5*sprite_width,y-0.5*sprite_height,x+0.5*sprite_width,y+0.5*sprite_height,oPlayer2,true,false))
{
    if (tagged = 1)
    {
        tagged = 0;
        oPlayer2.tagged = 1;
    }

    if (tagged = 0)
    {
        tagged = 1;
        oPlayer2.tagged = 0;
    }
}
I only have this code in oPlayer1 since I'm afraid that if I put it in both it will mess up the game.

My problem:
If I play the game and the tagger and the other player bump into eachother, it works perfectly fine. The tagger becomes the non-tagged player and other way around. But after this it doesn't work another time. The collision part works only once. I also tried the same piece of code without the if statement in a collision event but it gives the same result.
Can anybody help me with this problem?
And does anyone perhaps have a tip for me to make my code easier?

Thanks in advance,
Pim
 
Top