- Home /
OnTriggers hit wrong
I have had a lot of problems with physic 2D events, there is the newest one scenario but samekind of problems would be in very difrent kind of scenarios.
Scenario: I have gameobject with rigidbody2D and collider, under that there is gameobject with second collider which is on trigger mode (note that these two colliders dosen't react to each other since that is disabled by layers). Now my main gameobject goes throw another gameobject with trigger collider (no rigidbody). And of course every physic related components are 2d versions.
Now I have OnTriggerEnter, Stay and Exit functions on my main gameobject and I ESTIMATE that I get first Enter, then Stay for everyframe when colliders are inside each other and finally Exit.
But what I get:
Enter Enter Enter ... Enter Enter Exit
And just in "you just have type in your code" case here is my event code:
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("Trigger enter");
}
void OnTriggerStay2D(Collider2D other)
{
Debug.Log("Trigger stay");
}
void OnTriggerExit2D(Collider2D other)
{
Debug.Log("Trigger exit");
}
using 2d in unity is a waste of time in my opinion, its just broken to a degree... anyway, what is the question... i cant make out what you want ?
Answer by Pyrian · Apr 30, 2014 at 05:03 AM
This is apparently a common bug for colliders whose positions are changed in code - they tend to generate multiple Enters that should be Stays. You'll just have to treat subsequent Enters as Stays until you get an Exit - per Collider2D other, if there can be more than 1.
Your answer
Follow this Question
Related Questions
2D sprite movement stuttering 3 Answers
Physics2D.OverlapAreaAll/NoAlloc fails detecting object in puzzling manner 1 Answer
Many 2D rigidbodies optimization 1 Answer
How to make a collider be is trigger to some certain layers but be normal to others? 2 Answers
Get information on ignored collision 1 Answer