x


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?

more ▼

asked Feb 08 '10 at 01:03 PM

Mattivc gravatar image

Mattivc
1.7k 55 60 67

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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 );
}
more ▼

answered Feb 08 '10 at 02:32 PM

duck gravatar image

duck ♦♦
40.9k 92 148 415

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5059
x1865
x1525

asked: Feb 08 '10 at 01:03 PM

Seen: 5716 times

Last Updated: Aug 13 '11 at 11:18 PM