- Home /
Is it possible to check how much a trigger is filled by %?
Is it possible in C# to check for a box collider turned into a trigger being a certain percent full and running code based on that being over a certain % (Say 85 or so)?
My original idea was either a lot of little triggers that would make up the 100% and each time one is triggered it increments a value and deactivates that trigger so it cant flood it. Once the incremented number hits 85 you know 85% of the triggers have been hit but this will drop the accuracy because it might not be 85% filled but 85 triggers are hit.
I also thought raycasting but not to sure on that. Any ideas from you guys and girls?
Answer by Bunny83 · Mar 31, 2016 at 11:22 AM
How do you define full? Geometry in the scene doesn't consist of volume. It's just a bunch of triangles. Only the surface of an object is defined. Colliders do represent some sort volume but the purpose of the physics system is to detect collisions / overlaps in order to create a penalty force to simulate physics. Triggers do the same but instead of calculating a force they just send a message when a collision happens.
Colliders can be quite complex. For example a MeshCollider can have a non regular shape where it's extremely difficult to calculate the volume / boundary. A similar problem happens with compound colliders. They can already intersect each other. Since in a compound collider multiple colliders are treated as one, how would you treat the overlapping volume inside the compound collider itself?
So the answer is no, Unity doesn't have something like that built-in. You would have to calculate that yourself. Even if you only use box colliders, calculating the shape of the overlapping volume can be very difficult if your colliders can be rotated. If all colliders are axis aligned it's way simpler.
All of them are axis aligned, no rotation of any object in the game world. Thanks for the response, do you believe my method of 100 triggers would be sufficient?
Your answer
Follow this Question
Related Questions
How to Find Owner of a Trigger? 1 Answer
Check for collision while animating 0 Answers
Animation with frozen player ?? 0 Answers
Align to grid in runtime problem 1 Answer
How to check if a raycast is not hitting any tagged colliders? 0 Answers