- Home /
what is a raycast
how do you use a raycast and what is it used for
Answer by maikkel · Feb 20, 2012 at 10:07 AM
There are many different applications for ray casting.
its basically what it says: you define a starting point and a direction. Then an imaginary line is drawn with these parameters. If the line at some point intersects with a collider, you get a hit object which tells you exactly what was hit and where (world position), and the length of the Ray (line).
This can for example be used to find out if an object is in the player's line of sight, or to check distances (distance from player to edge of a cube). Also in a shooter you can use it to check if the enemy was hit without having to simulate a physical bullet.
Since I often work on mouse based games, I use it mostly to detect mouse clicks on objects and get the exact position where it was clicked.
for more information check out the script reference (raycast can only be used in scripting): http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=raycast
Your answer
Follow this Question
Related Questions
Creating a Ray Gun 1 Answer
LineRenderer. Problem with ray displaying 2 Answers
JS Script only work in Editor 0 Answers
Debug.DrawLine problem 1 Answer
interesting raycast question 2 Answers