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 nikroth · Dec 28, 2013 at 04:29 PM · collisionboundsintersectionintersectcolliding

Problem with getting colliding objects

Hello, I have a mine which damages in a radius. When I click a button the mine explodes and I have to check what is colliding with the mine radius.

I tried making a Primitive.Sphere with the radius of the blast. But i can't make the check if that sphere collides with another objects.

I tried looping through the other primitive objects and try sphere_mesh.bounds.Intersects(rectangle_mesh.bounds) and my_sphere.renderer.bounds.Intersects(my_rectangle.renderer.bounds) but these methods don't work very accurately because the bounding box is not rotating (it just expands and mesh.bounds is in local space and doesn't rotate too)

I dont want to use OnCollisionEnter and OnCollisionExit or triggers. I want to make it in utilities function.

I just want to check if there is an object touching the blast radius.


In my opinion there are two options: 1. mathematical way to get the lines/points of the objects and see if they go through the circle 2. make some kind of intersections of the primitive objects

I preffer the mathematical way because i can make the checks even on the server (where i don't have GameObjects only values) and then the server can make the check and return the damaged units. But the problem with the mathematical way is that the rectangles rotate...

The idea I have is to take the sides of the rectangle and rotate them the right way and make intersection between circle and lines (and line with line)

But I am not good at math and I can't do it. And i really think that the mathematical way is the way to go.

Has anyone done such mathematical intersection scripts ?

Any help would be apreciated.

Comment
Add comment · Show 1
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 nikroth · Dec 28, 2013 at 04:34 PM 0
Share

So i think that the question is a two part question

  1. Can someone tell me how to take the corners of a rotated rectangle (i know its center position and the localScale)

  2. Can someone tell me how to make the mathematical intersection of the lines between the points and another line/circle.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nikroth · Dec 30, 2013 at 05:00 PM

I solved it! So i get the coordinates ot he cornes of the rectangle (as told above) And then i make Rays from one point to the other And the rays have distance equal to the distance between the points

And after that i check if those rays intersect another object.

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 nikroth · Dec 30, 2013 at 05:11 PM 0
Share

I will apreciate it a lot if someone gives me a mathematical way of checking intersection between: line and another line and line and circle

in C# preferably :)

avatar image
0

Answer by robertbu · Dec 28, 2013 at 04:32 PM

You talk about rectangle and circle, so I cannot tell if this is 3D or 2D. The typical 3D solution is to use Physics.OverlapSphere().

The function will return a list of colliders that are within a specified radius of a specified point.

For 2D, there is Physics.OverlapCircleAll().

Comment
Add comment · Show 4 · 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 nikroth · Dec 28, 2013 at 04:39 PM 0
Share

I am talking about 3D and OverlapSphere checks the bounds but the bounds are not accurate because they dont rotate.

avatar image robertbu · Dec 28, 2013 at 04:50 PM 0
Share

I know the manual says it only check the bounds, but the manual appears to be mistaken. I just ran a quick test to be sure, it was testing against the mesh collider or box collider, not against the bounds. Do your own test.

avatar image nikroth · Dec 28, 2013 at 04:58 PM 1
Share

Okay it is a solution for circle against rectangle check but there is no OverlapBox method for rectangle agains rectangle.

Is there a way to get the corner points of a rotated rectangle ?

avatar image robertbu · Dec 28, 2013 at 05:10 PM 0
Share

Given the local (i.e. un-rotated) coordinates of the corners, you can use Transform.TransformPoint() to convert them to world coordinates. You can also use Transform.InverseTransformPoint() to convert them back to local coordinates of another game object.

avatar image
0

Answer by nikroth · Dec 28, 2013 at 06:54 PM

An idea that i have is: Get the points calculated from the center

poin1 = posision.z + height/2 , position.x - width/2 and so on....

(every Y coordinate is 0 to check only 2D coordinates)

and then rotate the points around the center with the function from this post: The Post

But now comes the question how to check if lines between the points intersect another line or circle

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.

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

Check if an Object is intersecting any other object 0 Answers

What's the best/easiest way to do something like Bounds.Intersects but accounting for rotation? 1 Answer

Check if mesh.bounds intersect a plane 1 Answer

How can i detect if 2 object hit eachother from a script which is not attached to either one of the objects? 0 Answers

Problem with objects colliding and IsSleeping (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