Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Harry64 · Jan 19, 2014 at 01:47 AM · vector3detectionboxempty

detect if a "Empty" is inside a box or trigger?

is there a way to detect if a Empty is inside a box?

I dont want to use collision detection because that would need the physic engine and I would need to use this on many gameobjects.

I want that this empty or the box can detect this so I can change the texture of this object that holds this Empty. there are more such boxes side by side and if I would use a collision detection or a trigger detection this would produce errors because if I would just touch the next cube with my object and would then go back it would change the texture to the next one and that is what I try to avoid.

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
Best Answer

Answer by robertbu · Jan 19, 2014 at 02:58 AM

There is a bunch of missing information for me to give you a detailed answer. One approach is to test the position of the empty game object against the bounds of true collider. I don't know how you are referencing the empty and the cubes, but something like:

 if (collider.bounds.contains(other.position)) {
     Debug.Log("Point inside collider bounds");
 }

Note I believe this bounds is axis aligned, so this is not a perfect solution if there is any rotation in the cubes. An alternate solutions that is a bit more accurate: transform the position of the empty game object into local space (Transform.InverstTransformPoint()), then check it against the bounds of the mesh (Mesh.bounds).

Comment
Add comment · Show 8 · 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 Harry64 · Jan 19, 2014 at 03:46 AM 0
Share

hmm... almost. I think you gave me the right direction ^_^

btw the cubes I sayed are not necessary to be displayed or real there. they all axis-aligned bounding boxes (AABB). I will display the cubes by Gizmos.

I just need to know in which AABB the empty is and send to the empty some informations like "change texture to red" or something.

avatar image robertbu · Jan 19, 2014 at 03:57 AM 1
Share

If you have an array of axis-aligned bounding boxes, just cycle through the array and use Bounds.contains() to check to see if the point is within the bounds.

avatar image Harry64 · Jan 19, 2014 at 04:36 AM 0
Share

like

 var Emptys = new Array();    // I would later remove or add Objects with emptys
 
 var aabb = Bounds (Vector3.zero, Vector3 (1, 2, 1));
 
 foreach(var object : Vector3 in Emptys)
 {
     aabb.bounds.contains(object);
     if (aabb.bounds.contains == true)
         send infos
 }
 

but how big would be the impact on the system when I have like 100-200 objects with that empty on it and like 40-80 Bounding Boxes? I would only need to check every 3 or 4 fixed update steps.

avatar image robertbu · Jan 19, 2014 at 05:38 AM 1
Share

First off, don't use the 'Array' class for this. It is slow and untyped. Use the .NET List class. As for speed, you'll have to test to see. Even if you don't have the rest of your logic figure out, it is easy to create the 80 BB and 200 object and test on your target platform. If it is too slow, try spreading the whole check over multiple frames. Given what you are doing here, there is also the possibility of doing it in another thread (not coroutine). And there are other data structures that can help you.

avatar image robertbu · Jan 19, 2014 at 10:37 PM 1
Share

This is getting a long ways from the original question. I suggest you open it as a new question with a detail explanation of what you want. Yes it is possible, but I don't understand enough of the particulars from your comment to indicate how you should accomplish your task. The List class has a number of methods for finding things in the list. Reference link:

http://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx

Show more comments

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

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 can I compare a Distance i measured using Vector3.Distance with a number 2 Answers

how do i correctly use a box collider 1 Answer

Simple Colliders Question 1 Answer

how do i correctly use a box collider 0 Answers

Vector3 Array Empties Its Self Immediately After Being Initialized 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