x


Raycast Collision-Detection

I have this set up so using the left mouse button fires a raycast from the camera. I have no idea how to check for collision with the raycast and a gameobject. I've looked everywhere, And I'm completely lost.

function Update () {

if (Input.GetButtonDown("Fire1")) {

var tbbeam : Ray = Camera.main.ViewportPointToRay (Vector3(0.5,0.5,0));
var hit : RaycastHit; Physics.Raycast (tbbeam, hit); if(RaycastHit.point(Vector3(0,0,0))){ Debug.Log("Hit."); }

Debug.DrawRay (tbbeam.origin, tbbeam.direction * 10, Color.white); }

}

P.S., I am a beginner. PLEASE HELP ME. I'VE BEEN GRUELING OVER THIS FOR HOURS.

more ▼

asked Feb 23, 2011 at 07:00 AM

Irsan gravatar image

Irsan
75 102 86 93

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

1 answer: sort voted first
more ▼

answered Feb 23, 2011 at 01:42 PM

spaceshooter gravatar image

spaceshooter
324 131 115 124

(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:

x5109
x2995

asked: Feb 23, 2011 at 07:00 AM

Seen: 6415 times

Last Updated: Feb 23, 2011 at 07:00 AM