Two Triggers Colliding

Options
Hi.

I have been testing and testing different strategies and have decided to get some suggestions on what is the best course of action. Here is the issue.

I have players in a Room that have the same player controller class attached to there object and I need to detect when they hit and only allow the player that has the greatest size (rigid body mass) destroys the other one. Locally the issue wasn't a problem in testing, as during the OnTriggerEnter2D process it seemed that the first one that entered the trigger was able to do the first calculation on size and destroy the other object before its own calculations took place...

So now during network coding it seems that I am getting multiple checks on the trigger event as the first process doesn't destroy the other object in time and all hell breaks loose... I am trying to build proper trapping to signal the other's trigger to abort it's process and well long story short I have yet to achieve 100% working trigger processes....

During the trigger event I have been accessing the other objects class code

hitobject = col.gameobject.getcomponent<otherclass>();
hitobject.isDead=true;

and trying to setup a boolean flag that gets triggered like a "isDead=true" flag so that during player number 2's trigger process things can get aborted... just it seems things are not working how I would expect them too. Very frustrating....

another question...

lets say player one has killed player 2 during the trigger event... and I sent a RPC to the masterclient to destroy the player... should I also destroy the object locally or wait for the network to destroy the object?

Thanks alot!

Comments

  • Tobias
    Options
    You need to decide which of the colliders is responsible to send a message to resolve the event "we collided". Let's say the client with the bigger collider has to send a "i ate you" message. The other doesn't do anything until it gets the message (it's explicitly not sending anything when it notices it's smaller).
    Then, the bigger one has to detect the collision, find that it's bigger and decide if it eats the other or not. When it eats the smaller, send a message. In either case, flag the collision with that player as "done" and keep that flag for some time or until both moved away from each other again.

    When you collide with multiple players, this is going to be interesting but you can probably still resolve it with "the bigger one updates the other".
    Order of RPCs is fixed when they are sent via the server. This is used in the Pickup Demo. This can be used to resolve more complex collisions, I think: Simply execute "eat" messages in the order they arrived and then skip any that's no longer valid (because A maybe ate C before B could).
  • Thanks for your feedback. I did test out the pickup demo a few days ago and did see some interisting code. I think I managed to get a initial working system in place but I have only really tried it with 2 players... larger tests may show that there is more work to be done. lets say..

    A = 10 in mass
    B = 20 in mass
    C = 30 in mass

    when A touchs B (b touchs at the same time) as they both "touch" so both colliders triggerEnter event will be fired... so lets say A runs first.. and figured out that A is smaller.... then I am trying to determine if I should let A trigger B's eat code... or just quickly abort the A's eat logic and let the B trigger run it's own eat code and self determine that it is larger so it is eat... this is my current situation.. and it seems to work...

    if getting A to process both A and B's eat code may cause B to double eat... as A will be in essence feeding B while B is already in a "About to eat" state.. ahahah

    ohh man. so far so good though.

    but just to complete this.. I am wondering if I should be just letting the system network destroy the eat object and simultaneously set the object to be SetActive(false) ... or just let the network destroy kill the object...

    Thanks again.