- Home /
hot to use raycast
how to return ray's position of intersection in the plane
Answer by Jesse Anders · Oct 24, 2010 at 11:45 AM
Look at Plane.Raycast() and Ray.GetPoint(). (Note that it's pretty easy to find this sort of information in the documentation, and checking the documentation will usually be quite a bit faster than waiting for an answer on Unity Answers.)
Answer by lhk · Oct 24, 2010 at 12:48 PM
You alse could perform the Raycast and use a RaycastHit object to get the informations. In the documentation they show this code
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, -Vector3.up, hit)) {
var distanceToGround = hit.distance;
}
}
As you see you can use a RaycastHit object as an additional parameter. The member variables of RaycastHit can be found in the documentation, too. For example you could use
point The impact point in world space where the ray hit the collider.
what different between Plane.raycast() and Physics.raycast()?
why the parameter of Plane.raycast() don't have Raycasthit.how to get the information of ray???
Plane.Raycast() performs a simple test between a ray and a geometric plane. The parametric point of intersection (if any) is written out by the function. You can get the collision point using Ray.GetPoint() (or by computing it manually), and the collision normal is simply the plane normal. Since there is no other meaningful information to return, there would be little point in using a RaycastHit object (which includes a variety of other information that wouldn't be relevant here, such as a collider reference and so on).