[SOLVED] Shooting fail (Due to camera setup)

Hi, so I’ve set my camera to respond to both the WASD and mousemovement, for everyone that’s played Counterstrike, it is of a similar function, if not, then here’s a brief explanation
W: Forward
A: Strafe left
S: Back
D: Strafe right.

Mouse moves right = Turns right
Mouse moves left = Turns left (Both concept similar to steering).

I’ll paste the code for the camera if needed.

Anyways - The real question is when I shoot a clone from the spawnpoint (the spawnpoint is set within the elemental staff) it shoots with the WASD, but when I turn with the mouse, it shoots from it’s last know location with the WASD. So how do I make my camera & fire understand that when I turn with the mouse, you shoot at what he’s looking at rather than shooting backwards :confused:

var projectile : Transform;
    var bulletSpeed : float = 20;
    
    function Update () {
        // Put this in your update function
         if (Input.GetMouseButtonDown(0)) {
    
        // Instantiate the projectile at the position and rotation of this transform
        var clone : Transform;
        clone = Instantiate(projectile,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
    
        // Add force to the cloned object in the object's forward direction
        clone.rigidbody.AddForce(clone.transform.forward * 1000);
        }
     }

UPDATE -

I changed the following line

    clone = Instantiate(projectile,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);

into

 clone = Instantiate(projectile,GameObject.Find("spawnPoint").transform.position, transform.rotation);

Now that allows me to shoot when the mouse movement changes, but upon shooting it doesn’t shoot straight anymore!

Anyone got any ideas?

[SOLVED] - I adjusted my spawnPoint, apparently it was upside down… Rofl. Blah.

You have to instantiate the clone also at the transform.rotation your looking at. So i think you should ad GameObject.Find(“spawnPoint”).transform.rotation after the position when spawnpoints points in the direction you want the clone to move in.

Adapted from the docs, TransformDirection :

   // Calculate the x-axis relative to the camera
var cam : Transform = Camera.main.transform;
var cameraRelativeForward : Vector3 = cam.TransformDirection (Vector3.forward);
// Apply a force relative to the camera's x-axis
rigidbody.AddForce (cameraRelativeForward * 1000);