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
2
Question by IgorAherne · Jan 08, 2014 at 12:27 AM · raycastdetectioncustomtrace

How does a raycast really work?

Does anybody know how to implement a custom version of Unity's raycast or UDK's Trace?

Might be an overwhelming and a very complicated question, but how would I check if my ray or 3D vector would return an intersection with something like a polygon?

Here is the source I've found http://www.permadi.com/tutorial/raycast/rayc1.html

Thank you!

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

3 Replies

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

Answer by robertbu · Jan 08, 2014 at 12:38 AM

It depends on what you are trying to do. I assume your polygon is on some plane. You can use Unity's mathematical Plane class to find the point on the plane. They you can test to see if the point is inside or outside the polygon. Google "point inside outside polygon" and you will find many hits (some with source you can translate).

As an alternate, you could just build the polygon into a mesh and allow Unity's Physics.Raycast() or Collider.Raycast() to do the detecting. Here is a Wiki script that might be helpful if you go down that road.

http://wiki.unity3d.com/index.php/Triangulator

What approach you take (and there are others plus refinements of these two) is highly dependent on the nature of your app.

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
avatar image
7

Answer by aldonaletto · Jan 08, 2014 at 01:54 AM

Physics.Raycast or UDK's Trace are related to spatial search, differently of the text you've linked (which's actually about rendering, and is pretty outdated). Physics.Raycast casts an imaginary ray from the origin in the desired direction and checks whether it hits any collider. In many physics engines (and probably in Unity and UDK) it's done as a search in an internal database where the engine keeps info of all colliders in scene, arranged so that spatial searches may be done quickly. The ray is first tested against the bounding box of each collider; when it's found that a bounding box is hit by the ray, the test is done against the actual collider shape. Spherical, capsule and box colliders are tested with relatively simple operations, but mesh colliders must be tested triangle by triangle.

Implementing a custom 3D raycast test is for sure a pain in the ass - maybe this paper helps you to find the bounding box intersection. A 2D raycast is fairly less complicated, but still a hard job - google for line-polygon intersection algorithms.

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
avatar image
-1

Answer by ZorNiFieD · Jan 08, 2014 at 12:56 AM

Debug.DrawRay()

Unity Reference Doc

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

20 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

Related Questions

detection raycast too late 2 Answers

Checking detection of gameobject correction 2 Answers

Decals on corners 1 Answer

raycast hit not detecting && Nav mesh agent ai stealth 1 Answer

I don't know why i can't detect by ray sth. tagged, 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