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 /
This question was closed Feb 17, 2018 at 03:48 AM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by The_sky · Sep 07, 2013 at 07:58 PM · raycastraycasthit

I don't understand Ray,RayCast,RaycastHit ??

Help me!I don't understand Ray,RayCast,RaycastHit ??

Comment
Comments Locked · 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 DDP · Sep 07, 2013 at 08:05 PM 1
Share

What are you trying to do exactly?

That may help:

http://docs.unity3d.com/Documentation/ScriptReference/Ray.html http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit.html

avatar image fafase · Sep 07, 2013 at 08:08 PM 2
Share

I would recommend to read the docs.

Ray is just an entity representing a line with a start point and a direction but no end.

Raycast is the method you use to cast a ray (or a vector) from a point in a direction with distance (or not) and then reports if the ray hits something.

The RaycastHit is the structure you use in the raycast method to store info on the collision.

So you call Raycast with a ray and if the ray hits something then you store the info in the raycast hit struct.

1 Reply

  • Sort: 
avatar image
11
Best Answer

Answer by aldonaletto · Sep 07, 2013 at 08:31 PM

The ray is a geometric creature: a line starting at some point (the origin) and following indefinitely in some direction. Physics.Raycast is a test that verifies whether some collider is hit by the ray specified, and RaycastHit is a structure that Raycast fills with info about the first object hit by the ray - it has invalid values if nothing hit, thus only read it when Physics.Raycast returns true. A typical use for Raycast is to detect which object was clicked:

 function Update(){
   if (Input.GetMouseButtonDown(0)){ // if left mouse button pressed...
     // get ray starting at camera position and passing through the mouse pointer:
     var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     var hit: RaycastHit; // allocate variable RaycastHit
     if (Physics.Raycast(ray, hit)){ // if something hit...
       print("Clicked on "+hit.transform.name); // print its name
     } else {
       print("Nothing hit");
     }
   }
 }

Comment
Comments Locked · 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 The_sky · Sep 08, 2013 at 05:13 AM 1
Share

Thanks you for answer.

avatar image Grant-Christie · Feb 16, 2018 at 11:00 PM 0
Share

Great answer

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

Raycast is always returning 1 (for normals) 1 Answer

A node in a childnode? 1 Answer

Something fishy with RaycastHit 1 Answer

Rays do not detect terrain and prefabs do not spawn where wanted 1 Answer

RayCasting from camera to player 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