Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Matthewek · Oct 31, 2015 at 07:00 PM · 2dmathboundscontains

2d - Check if point is within bounds, rotation

Hello, I need to detect when one object is within/inside another,

alt text

it works by checking bounds.Contains method (I check if bounds of green box, contains min and max bounds of yellow one)

However in my scenario, both boxes can be rotated, and it basically means following approach will be useless, since unity`s documentation says, bounds are:

 > An axis-aligned bounding box, or AABB for short

is there any other method to calculate and detect that? I could use 2d colliders and detect that on collision enter, but I am looking for simpler way to calculate it.

Thank you.

1.jpg (4.9 kB)
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
3
Best Answer

Answer by Statement · Oct 31, 2015 at 07:25 PM

If you just need to test a point vs a bound, transform the point into the same transformation space as the bound. Obviously you can't use the renderer bounds since it keeps resizing. Perhaps a Rect would suffice.

If you need to to test two 2d boxes, you could do a simple line test for intersection, based from the corners of the box and if any line intersect, it overlaps. You can do a containment test such that if all 4 corners of box is inside the other box, it's contained (no intersection occur in containment). Note that either of the boxes could be contained within the other so you need to make the test for both (is A contained in B or is B contained in A?).

These are general problems that isn't Unity specific and you can find lots of examples online.

A simpler way might just be to use a BoxCollider2D, and use the provided functions IsTouching or OverlapPoint.

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 Matthewek · Nov 01, 2015 at 07:23 PM 0
Share

Thank you, isTouching using box collider 2d, turned out to be the easiest way, cheers.

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

45 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

Related Questions

Keep Top Down 2D camera in bounds of background sprite 3 Answers

Advanced placing position from the same angle of target position 0 Answers

How to calculate vector perpendicular to a direction vector? 2 Answers

List.Contains not working as intended 0 Answers

How do you determine the x,y co-ordinates of a sprite's boundaries? 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