x


How can i make a raycast in my fps game?

I want it so there is a ray cast in the middle of the camera. The raycast goes far but not infinite. When i shoot my gun, the bullet goes towards where the raycast hits an object. can any one help me with this? Thanks!

more ▼

asked Apr 12 '11 at 11:21 PM

niceperson87 gravatar image

niceperson87
12 7 8 8

Are you sure you ned a raycast if you're going to instantiate a bullet? You could probably just send out the projectile forward.

Apr 12 '11 at 11:50 PM Jason_DB

And add on OnCollisionEnter... It'd be just as good.. Then have it destroy itself after a certain amount of time...

Apr 13 '11 at 12:53 AM Justin Warner
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
    function Update()
        {

 if(Input.GetMouseButton(0))

      {
 var ray = camera.ScreenPointToRay(Input.mousePosition);
 var hit : RaycastHit;

 if(Physics.Raycast(ray,hit))
   {

if(hit.transform == instruction)
   {
   inst = true; 

   }


 if(hit.transform == start)
   {

   Debug.Log("start");  
   }

   }

   }




   }
more ▼

answered Apr 13 '11 at 06:11 AM

robertmathew gravatar image

robertmathew
571 35 39 51

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

x1525
x1171
x307
x129
x103

asked: Apr 12 '11 at 11:21 PM

Seen: 1588 times

Last Updated: Apr 12 '11 at 11:21 PM