Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by test84 · Oct 27, 2012 at 03:51 PM · colliderscontain

How to detect that my object is completely inside a box?

Hi,

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.

Thanks in advance folks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Oct 27, 2012 at 04:21 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image test84 · Oct 27, 2012 at 05:32 PM 0
Share

Thanks for your answer but:

1) I can't check if they are near the center because in the actual game, this may not happen and I will it.

2) $$anonymous$$y dragged objects will have like sphere colliders Shrinking my trigger will not work as well because I use that trigger to find out about the collision itself.

3) About the four walls suggestion, the same problem will happen that how you will know when an object is passed from that specific wall, hence you have to know when it's inside the wall and same problem occurs.

avatar image Owen-Reynolds · Oct 28, 2012 at 04:12 AM 0
Share

So are your boxes much larger than the objects? Even then, say you have 5x5 boxes and size 1 objects. A 4x4 trigger will give a pretty close "fully inside" check.

Each wall is one thin side, so as an object moves into the box it starts not in the wall, in the wall (passing through it) and then outside the wall again (in the box.)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

physics.OverlapSphere colliders 1 Answer

What are best practices for getting your character to not fall through the floor? 1 Answer

Strange Collisions in 2D 1 Answer

An object with multiple rockets? 1 Answer

Trigger-based vehicle ai? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges