#Can't properly detect if a point is within a Box Collider's bounds

1 messages · Page 1 of 1 (latest)

feral current
#

I'm trying to detect if a point is within my box collider, with this function:
public bool PointInside(Vector3 point) {
return collider.bounds.Contains(point);
}
However, it always returns false, no matter what. The gameobject this function is run on has the collider as a trigger, and it is not rotated or scaled at all. I double checked the bounds of the collider are correct, which they are using this script https://discussions.unity.com/t/bounds-contains-is-not-working-at-all-as-expected/671128/5. The point passed into the function is in world-space, from a transform.position.

mint prairie
feral current
#

Tried with both
return collider.bounds.Contains(transform.position - point);

and
return collider.bounds.Contains(transform.worldToLocalMatrix * point);

to no luck. I can't use overlap queries, since that could get extremely expensive as there are many AudioRooms being updated every few game Updates. there'd be over 100 audio rooms, so i want to try and stick to AABB style detection if i can

mint prairie
#

And if you're gonna go all out with the optimization, just having a collider in the scene gonna make impact on performance, so get rid of it as well.

feral current
#

good point, thanks.
I tried this
public bool PointInside(Vector3 point) {
bool inside = false;
foreach (Collider collider in Physics.OverlapSphere(point, 0.1f)) {
if (collider == this.collider) {
inside = true;
break;
}
}
Debug.Log(inside);
return inside;
}
Still not working. I'll try my own implementation for AABB detection.
Also, did try transform.InverseTransformPoint(), still no result

mint prairie
#

Print the relevant values or place a breakpoint and step through the code.

feral current
#

omfg im an idiot. What happened, was in my AudioRoomManager, when i added my code for skipping updates on intervals and checking all the rooms, i accidentally overwrote my code that would update the listenerPos, so the rooms were always checking against a point at 0,0,0, which of course would always be false. My bad, sorry for wasting your time. But I definitely did have to convert to local space for the collider. Works fine now.

thorn trellis