Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 airoll · Aug 21, 2021 at 06:10 PM · rotationcolliderbounds

How to project the position of a point relative to a rotated collider using its bounds?

Hello, let's say I have a point point and a rotated box collider collider. What I'd like to do is be able to project point such that if I generate a OBB bounds of the collider, I can calculate things like OBBBounds.SqrDistance(point) or OBBBounds.IntersectRay(ray).

I've tried using something like

 Vector3 localPoint = colliderTransform.worldToLocalMatrix.MultiplyPoint(point);
 OBBBounds.center = Vector3.zero;
 sqrDistance = OBBBounds.sqrDistance(localPoint);

However, this doesn't seem to quite work, and I think it's because colliderTransform.worldToLocalMatrix.MultiplyPoint(point) is not the right transformation. However, I can't figure out exactly what is the right transformation. I think it's because OBBBounds.extent that is world space, while localPoint is in local space.

Would you be able to help my identify what the right transformation is?

As an example, let's say I have a collider at (41.7 ,7.1 ,42.1), with rotation (0, 180, 90) in degrees, and my point is at (46.0, 5.7, 47.0). When I apply the above code, localPoint = (-1.4, 4.3, -4.9), and I would expect that it should actually be at (-4.3, 1.4, -4.9).

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 Bunny83 · Aug 21, 2021 at 07:27 PM

I think you have the wrong idea about Collider.bounds. It returns the worldspace AABB (axis aligned bounding box)- The collider class does not provide you a localspace bounding box. What you're currently doing is projecting your worldspace point into the local space of the collider and then you test the local space point against a worldspace bounds which of course doesn't make much sense.


It's not quite clear what your exact usecase is. However the Collider class does have a Raycast method as well as a ClosestPoint method that directly takes a worldspace ray / worldspace point


Of course if, for some reasons, you really need a bounds instance that represents the localspace AABB of the box collider, you have to construct this yourself by using the box collider parameters like that:

 Boxcollider boxColl;
 
 Bounds localSpaceBounds = new Bounds(boxColl.center, boxColl.size);

Of course this bounds would only work when everything is in the same local space. So all positions or direction vectors need to be in the same local space.

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 airoll · Aug 21, 2021 at 08:49 PM 0
Share

Hi @Bunny83 ah yes you are correct - what I meant to say was that I had the localSpaceBounds of the collider as you mentioned, and I was trying to transform my point into that local space. I recognize that there is a ClosestPoint and Raycast method of the collider but I actually don't have access to the collider in the script I'm trying to run this from (all the position, rotation, and bounds information are extracted elsewhere).

How would I transform this point into the local space of the localSpaceBounds?

avatar image Bunny83 airoll · Aug 22, 2021 at 04:43 AM 0
Share

Well, just like you did already. However this line makes no sense:

 OBBBounds.center = Vector3.zero;

The center of the bounds should also be given in local space coordinates. The center of a box collider is also in local space. So setting it to zero doesn't make any sense.


Though it should be obvious that all results you get from Bounds.ClosestPoint is also in local space since everything involved would be in local space.

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

196 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 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 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 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 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 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 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 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 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 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 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

Size of collider bounding box regardless of rotation 1 Answer

Character Controller slides sideways when it hits objects are angles different from 90 degrees 1 Answer

Converting Bounds.size to GUI? 0 Answers

Wheel Collider Rotation Problem 0 Answers

Percentage of Collider within a Trigger Area (C#) 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