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 /
avatar image
5
Question by Jordan Miller · Apr 22, 2010 at 08:58 PM · collisionraycastmathrayintersect

detect Ray Crossing? Intersecting?

I have 2 object that are casting rays, I need a way to know if those rays intersect, and at what point. Here's a birds-eye picture of the situation below. (http://s794.photobucket.com/albums/yy225/JaredShadrak/?action=view&current=raycollisiondetection.jpg)

I thought about creating a vertical plain along one of the rays but I'm not sure if that's the most effective way.

alt text

Comment
Add comment · Show 2
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 Jordan Miller · Apr 22, 2010 at 09:14 PM 0
Share

I thought of another way, but maybe there's a more efficient way. but maybe I could do this:

the units firing the raycast can point it slightly down. eventually both rays will hit the terrain mesh and if they cross, that will be reflected in where they hit the ground. once I have where they hit I can triangulate the coordinates and deter$$anonymous$$e the point at which they crossed each other. dude, that's awesome!

if you know of an easier way, please let me know, I don't wanna program that all.

avatar image Random Indie · Apr 23, 2010 at 06:19 AM 1
Share

might want to add the math tag to your question :)

1 Reply

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

Answer by Random Indie · Apr 23, 2010 at 05:29 AM

There are a few ways you could do this.

1) You could use the formula found here that gives the intersection point in 3d, however if you're not familiar with linear algebra it might look a little daunting. (even if you are, it's still messy when expanded). Do a find for "In three dimensions, the algebra becomes more complicated." It's about halfway down the page. of course, there's the issue that you're unlikely to have rays actually intersect, and given floating point errors they may never cross according to the computer.

2) You could ignore one component (say Y) and do a 2d line intersection (also available on the first link). Then once you have the point they intersect on the XZ plane, you could just see how far the two rays (at the intersection in XZ) are from one another given a tolerance. However, if the rays are near vertical this could make the floating point errors blow up so it might be a good idea to ignore X or Z if you're 45 degrees above the horizontal, if that's the case, the idea remains pretty much the same.

Your line/plane intersection would definitely work. All you'd have to do is find the point where the ray and plane intersect, then get the perpendicular distance from the ray (forming the vertical plane) to the intersection point on the plane. This should help. This is a more succinct version of the same thing.

Hope that helped, I'm hopped up on cold medication so I can only hope that made some sense. If not, I can try to clarify. No matter what though you're going to probably have to do some algebra (if that's a problem when I'm not so wobbly from the meds I can help out.)

Cheers

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 Jordan Miller · Apr 23, 2010 at 06:06 PM 0
Share

Thanks! this should really help!

avatar image Random Indie · Apr 23, 2010 at 06:56 PM 0
Share

Hey no problem. :)

Like I said if you need any help with the theory feel free to ask.

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

No one has followed this question yet.

Related Questions

How would I find the closest Vector3 point to a given Ray? 2 Answers

How can I determine how many colliders exist along a line? 1 Answer

Raycast for 2d with touch. 0 Answers

Casting a Ray in the direction of the movement 1 Answer

using Raycast to detect collision 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