- Home /
Raycast collision detection?
I want to instantiate an object at the raycast's point of collision. Here is the script I have so far:
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
var ray : Ray = camera.ScreenPointToRay (Vector3(200,200,0));
Debug.DrawRay (ray.origin, ray.direction * 10, Color.white);
}
}
Any help? I've seen sample scripts, but they're interfering with the fact that the raycast is coming from the camera. I am a beginner at this.
Comment
Answer by Jessy · Feb 23, 2011 at 11:45 AM
It doesn't matter that the ray is "coming from the camera". ScreenPointToRay creates a ray just like any other, with an origin and direction. Just take the last example from the docs and Instantiate something at hit.point.