- Home /
 
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!
Are you sure you ned a raycast if you're going to instantiate a bullet? You could probably just send out the projectile forward.
And add on OnCollisionEnter... It'd be just as good.. Then have it destroy itself after a certain amount of time...
Answer by robertmathew · Apr 13, 2011 at 06:11 AM
 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");
 }
 
                }
 
                }
 
                } 
 
              Your answer
 
             Follow this Question
Related Questions
raycast not doing good 1 Answer
Simulating gravity to Raycast bullet 3 Answers
How to Implement First Shot Accuracy? 2 Answers
How to get bullets to hit crosshair 2 Answers