I’m developing a game that you drag and drop objects into boxes and I have no idea what’s the best and most efficient way to detect whether my objects are in a box.
I’m well aware of colliders and I’m using BoxColliders and triggers to find out whether my object is touching a box but I want to detect the moment when my object (which we can assume to be sphere for sake of simplicity but later will be a mesh) is completely inside my box trigger/collider.
I read about “Contains” method of colliders but IIRC they just check if one single point inside that collider but I’m interested to know if the whole object is inside the collider.
A simple, crude way is to just check if you’re near the exact center of the box. Not perfect, but works surprisingly well.
If the dragged objects have capsule, box … colliders, simply shrinking your trigger will work. To work out the size, draw some pictures with your object not quite placed, and barely counts as placed.
If you’ve got oddly-shaped things and need each tentacle and tail to be completely in, that’s a tougher nut.
Could rig up an “inside me” collider using four box collider “walls.” Each wall adds one to the dragged object’s wallCount on enter, and subtracts one on leave. If your wallCount is 0 and your position is within the box bounds, you’re completely in. Bonus is you could “flash” the offending wall as a placement guide.