• 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 PapaD · Apr 05, 2011 at 06:38 AM · rigidbodyboundingbox

Axis Aligned Bounding Box Vs Object Orientated Bounding Box

Hi guys,

I'm trying to get the closest point on the bounds of one object to another game object. This is what I am currently trying out:

public class object1 : MonoBehaviour { void OnDrawGizmos() { Collider[] colliders = Physics.OverlapSphere(transform.position, radius);

     foreach (Collider hit in colliders) 
     {
         if( hit.CompareTag("Block") )
         {
             Gizmos.color = Color.red;
             Gizmos.DrawSphere( hit.ClosestPointOnBounds(transform.position), 0.1f );
         }
     }
 }

}

All this gives me is the AABB (Axis Aligned Bounding Box) of the hit object. Unity Uses the OOBB (Object Aligned Bound Box) for it's rigidbody collisions, but using hit.rigidbody.ClosestPointOnBounds only gives the AABB again.

Is there a way to get the closest point on the OOBB that isn't computationally expensive?

Or at the very least accessing the OOBB which is used by the rigidbody?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Statement · Apr 05, 2011 at 12:16 PM

I think you are misunderstanding the terms box collider and bounding box.

A (axis aligned) bounding box is used for quick culling of objects. This is the bounds you're trying to get the closest point from with that call, not the actual box collider data.

you could do like this though:

// ...

 Collider[] colliders = Physics.OverlapSphere(transform.position, radius);

 foreach (Collider hit in colliders) 
 {
     if( hit.CompareTag("Block") )
     {
         var dir = hit.transform.position - transform.position;
         var ray = new Ray(transform.position, dir.normalized);
         RaycastHit rayhit;
         if (hit.Raycast(ray, out rayhit, dir.magnitude)) {
             // rayhit.point now contains the closest point
             Gizmos.color = Color.red;
             Gizmos.DrawSphere( rayhit.point, 0.1f );
         }
     }
 }    

// ...

Comment
Add comment · Show 1 · 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 PapaD · Apr 14, 2011 at 07:49 AM 0
Share

Unfortunately while this does get the closest point on the surface of the colliding object to Object1, the point is in a line to the centre of the object.

As an example I've created a basic scene in which there is a box with a scale of x = 2, y = 10, z = 2 and a rotation of 45 degrees in the z axis. When Object1 gets close, the red sphere gizmo is not the closest point. :(

avatar image
0

Answer by Ray-Pendergraph · Apr 05, 2011 at 12:05 PM

I am not sure how the Unity engine performs collision detection but you could try using the AABB reported by Mesh.bounds.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Create and divide a bounding box into cells 0 Answers

Possible to Give Rigid bodies collision bounding boxes? 0 Answers

Rigidbody Collision Help 1 Answer

Collisions - bounce of walls but not from characters (while still reacting with them) 0 Answers

Rigidbody Problem , Please Help me ... 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