- Home /
Location of raycast collision.
I want to instantiate a GameObject at the location a raycast collide with the mesh collider. How can i get the location of the collision?
Comment
Best Answer
Answer by duck · Feb 08, 2010 at 02:32 PM
You need to pass a "RaycastHit" object into the raycast function, and then if the raycast returns as true, the RaycastHit object's variables will be filled with data about the intersection, including the "point" variable, which gives the raycast collison location in world space.
eg:
var hit : RaycastHit;
if (Physics.Raycast (transform.position, -Vector3.up, hit, 100.0)) {
Instantiate( sourceObject, hit.point, Quaternion.identity );
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612054829im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# Check Physics.Raycast Once 0 Answers
Raycasting from the sides of a GameObject 2 Answers
Raycast problems in my AI 1 Answer
Raycast 2D with origin inside the collider 1 Answer
Raycast length must be equal to the target distance 2 Answers