- Home /
Why are my OnTriggerEnter2D events firing only on android in a situation they shouldnt be firing?
I have been struggling with a collision bug that only happens when I install the game on an android device.
I have a very simple game set up like air hockey. Some objects to represent paddles, a puck, a couple of end zones for scoring, and walls. Whenever I move one of the paddles and collide it against the puck at a very low velocity, my ontriggerenter2d events are firing on my end zones even though the puck is nowhere near the end zones.
Here is my OnTriggerEnter2d function in my end zone controller script:
// EndZone
void OnTriggerEnter2D(Collider2D Other)
{
Debug.Log("EndZone::OnTriggerEnter2D " + playerNumber.ToString());
if (Other.gameObject.tag == "Puck")
{
Observer.SendMessage("Score", "" + playerNumber.ToString());
}
}
I'm not sure what other information could be relevant. I will provide anything asked for including my entire project if deemed necessary.
This bug only happens when I actually build to android, not when I run the game on desktop. Even if I'm using a tablet and unity remote to provide input.
Debug.Log(Other.GetInstanceID());
These type of collision normally related to unexpected collider. Check if it was Puck that hit Collider. $$anonymous$$ight be double collision(rigidbody + 2D Collision)
Hi. I've done that. In fact I've used android studio debugging to find that it is in fact both end zone triggers popping. Even if it were another collider, it shouldn't be sending the message since I check the tag of the gameobject so it shouldn't be a problem. It is the puck.
Here's something new I found out which I posted in the stackoverflow thread: when my paddle collides with my puck, I apply a force to the puck with AddForce. If I comment that line out, the bug doesn't happen. $$anonymous$$y triggers never go off.
Sound like kinematic fault in rigidbody if you have one. (mistakenly use add force in Update(), anything addforce to rigidbody should be in FixedUpdate())
Like if you seperate rigidbody + collider and render texture.
$$anonymous$$ight be texture and rigidbody is in different place when hit by paddle.