23.4 C
New York
Saturday, September 6, 2025

collision detection – Approach to test overlaps of a Collider2d that is not set to “is set off” in Unity


I’ve a system the place 2D physics objects are spawned, and I must know after they spawn outdoors of a area outlined by a field collider set to “is Set off”.

Utilizing OnTriggerEnter and OnTriggerExit to know if an object exits / re-enters the bounds (with another circumstances figuring out whether or not to kill the article when it exits the bounds), that stuff works high-quality.

Nevertheless, I am unable to detect when an object spawns outdoors of the collider (which I wish to permit, however simply know when it occurs).

I attempted the next within the Begin methodology of the spawned object:

Checklist outcomes = new Checklist();
_boundsCollider.OverlapCollider(new ContactFilter2D(), outcomes);
bool spawned_outside = !outcomes.Accommodates(_thisCollider);

Nevertheless, on the time that methodology runs, the bounds collider would not register it. In subsequent frames it is going to, however that is too late.

OverlapCollder cannot be run on the collider for the spawned object, because it is not set as a set off.

Is there any manner I can question the spawned object’s personal collider to find out whether it is in touch with the bounds collider?

I am unable to simply trivially reference the coordinates of the article and test in the event that they’re out of bounds, as a result of the bounds collider will transfer, and I wish to know with precision whether or not only a nook is overlapping or no matter, so I would want one thing that quantities to my very own easy collision system.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles