• 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
1
Question by ALLCAPS · Oct 20, 2013 at 06:53 PM · bounds

Bounds.contains not working?

Is there a pitfall to using an array of Bounds to find a players location? I am parsing Quake maps that contain bsp trees, and I have bounding boxes made for all the leafs in the tree. This results in a bunch of boxes, and I'm trying to see what one/ones the player is in. I setup a simple script to iterate over the array of bounds and check if the bounds.contains the maincameras transform.position, but even when I know for a face that the camera is inside one of the boxes, it shows me as being inside 0 of the bounds.

I also get different data if I Debug.Log the mins/maxs I'm using to make the boxes, and if I Debug.Log the mins/maxes of the boxes after they've been made. However when Gizmo.DrawWireCube-ing them they are in the correct spots.

I have never tried to use a "raw" bounding box like this, and I'm a little confused. I tried searching Answers and the documentation, but no dice. The script doc for Bounds makes it look so turnkey, but there's a gotcha I'm hitting somewhere.

Comment
Add comment · Show 9
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 Jamora · Oct 20, 2013 at 07:14 PM 0
Share

If you're parenting any GameObjects, the different values might be because of the parent-child relationship. The manual for Transform suggest (at the bottom) you set a parent's position to 0,0,0 before adding any children.

avatar image ALLCAPS · Oct 20, 2013 at 07:21 PM 0
Share

Neither the Bounds or camera being tested are children or parents. The script that generates the bounding boxes is attached to an object/empty (obviously) but it's sitting on the origin already.

avatar image rutter · Oct 20, 2013 at 07:33 PM 0
Share

Probably make sure the Bounds boxes are exactly what you expect them to be. Try drawing them out with gizmos, or at least sanity checking their values. One gotcha is if they're zero units thick on any axis, they can't contain anything.

avatar image ALLCAPS · Oct 20, 2013 at 07:35 PM 0
Share

I'm Gizmo drawing them right now, I have green wirecubes for each of the boxes, and I'm still not getting any hits when I iterate over them and check "contains".

avatar image Benproductions1 · Oct 20, 2013 at 10:21 PM 0
Share

How are you drawing them. From experience, it's usually a mistake in space conversions

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I keep an Ortho camera in a specific range when the ortho changes? 3 Answers

Checking if ground is 'level' 1 Answer

Imported mesh bounds size is alwasy too big and pivot point is not aligned 1 Answer

Shader LOD 1 Answer

How to stop view from scrolling when edge of view collides with a game object? 0 Answers


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