Laserfire not tracking if ship rotates

I know trajectory questions get asked 10K times a day, but I can’t seem to beat this into submission. All of my code is pilfered from several posts and the script reference and this is what works best so far. I tried to make the laser LookAt the target before sending it forward, but that didn’t help either.

Scenario:

  • I start my scene - my ship hasn’t
    moved - I select a target. The laser
    fire tracks correctly to any target
    selected.
  • I move my ship foward along z. The
    laser fire still tracks correctly
    even while the ship is moving.
  • I rotate my ship along x or y, the
    laser fire rotates in weird ways and
    I don’t hit the target. Tracking is lost.

Here is the logic:

Rigidbody clone = Instantiate (laser, transform.position, Quaternion.identity) as Rigidbody;
Physics.IgnoreCollision (clone.collider, transform.collider);
Vector3 destV = target.position - clone.position;
clone.velocity = transform.TransformDirection (destV);
audio.PlayOneShot (laserSound);
Destroy(clone,3.0f);

Can someone help me make it track even if my ship rotates?

You’re transforming destV to world space - but destV already was in world space, thus it gets rotated to crazy directions. Just remove the TransformDirection thing:

  clone.velocity = destV;

But to be more precise, you should use destV normalized and multiply it by the desired speed - or else the laser speed will depend on the distance: the closer, the slower.

  float speed = 10; // define the speed
  ...
  clone.velocity = destV.normalized * speed;
  ...