Shoot where to camera direction ?

I did the FPS tutorial but when i shoot the projectiles take off from the weapon to the direction where the weapon is looking. I want thet the direction be the direction where the user is aiming. I did this But donset work:

function Update()

    if( Input.GetButtonDown( "Fire1" ) )

     var ray = new Ray (cam.transform.position,cam.transform.forward); 
     var hit : RaycastHit; 

     if (Physics.Raycast (ray, hit, 100)) { 
        Debug.DrawLine (transform.position, hit.point,;

        var instantiatedProjectile : Rigidbody = Instantiate(
            projectile, transform.position, transform.rotation );


        instantiatedProjectile.velocity =
            transform.TransformDirection( new Vector3(0,0,speed));

        Physics.IgnoreCollision( instantiatedProjectile. collider,
            transform.collider );



Well I assume you are trying to shoot targets which are at your reticle's screen location. To do this you would want to get the screen location of your reticle (or the center of the screen if you don't have a reticle and just want to use the center of your screen) and then use the cam.ScreenPointToRay method to get the ray. Use that ray to look for your targets and it should work.

All you have to do is go into the first person controller on your scene panel, open it up, and drag your gun script onto the main camera. If you drag it onto the First Person Controller alone, it just points where the controller is pointed. If you drag it onto the camera, it will fire where the camera is looking at the time. Try it!

Check out the 3rd Person Shooter Example. It does pretty much exactly what you're looking for.

IIRC the pertinent game objects are the player, AimTarget, MainCamera, and the Third person camera controller script (can't remember it's name exactly but it's attached to the camera).

With some fenagaling you should be able to sort it out. It's like what shaKu suggested.