Tag player confusion, C# script

I’m trying to make a simple 1v1 freeze tag game. One of the players starts as “it” and once he tags the other person the player who was it then becomes “not it” and the player who was tagged becomes “it”. My problem is player 1’s bool called “isIt” is constantly tagged as true and I am unsure of why.

I added the script files. If anyone has any suggestions I’d be thankful. The scripts are basically similar, except one starts with someone in the start function.

2354376–159534–Player1Movement.cs (1.7 KB)
2354376–159535–Player2Movement.cs (1.7 KB)

What do these spit out in terms of Debug logs?

From a quick glance, you can conceivably collide while being “it” and remain it.

Let’s step through it:

  • Player 1 collides with player 2, triggering Player1Movement.OnTriggerEnter()
  • Player 2 is now “it”
  • Player2.OnTriggerEnter() begins as player 2 is also colliding with player 1, setting player 1 back to “it”
  • Both trigger enter messages are satisfied, but the state has not changed

Also, splitting these practically identical classes doesn’t make sense to me. Why not just have one class for both players?

It’s one class because I’m new and figured it would be easier to understand with two. If I get this working then I will make one class for both.
The first time they hit, player2 is not It, and player1 is.
The second time, and everytime after, player 2 is it and player1 is it.
Also, on the inspector(i believe its what it’s called), Player 1’s bool of “isIt” is never checkmarked afterwards, but it still says it’s true when colliding.
Whereas Player 2’s bool is consistently marked after the first collision.

Yep, that sounds entirely compatible with my theory. Someone correct me if I’m wrong but I think physics message order is deterministic?

How’s this - try putting in a timeout where the IsIt bool can’t change. Some variable you add Time.deltaTime onto on updated. When you go to set your opponents IsIt variable, check that this above something like 1. If it is above that, set it to 0. The upshoot of that will be that you can only change with player is “it” once per second, which should solve the issue.

I’m not entirely sure how to do this. I don’t know how to do what you are asking. It sounds great but I can’t figure out how to implement it.