Hello Trying to make homing missiles I've encountered weird problems. I've simplified it as much as I possibly can, and would really appreciate any help on this. Code (csharp): void Update(){ homing(); transform.position += this.transform.rotation * Vector3.up * speed * Time.deltaTime; //Propell projectile forward } private void homing(){ GameObject target = findClosestTarget(); Debug.DrawLine(target.transform.position, target.transform.position + new Vector3(10,10,0)); //Confirms that target is valid this.transform.LookAt(target.transform); //Problem occurs here. My projectile doesn't seem to turn at all. } this.transform.Rotate(new Vector3(0,0,5)); Is confirmed to make my projectiles fly in circles. Replacing transform.LookAt() with: this.transform.rotation = Quaternion.LookRotation(target.transform.position); makes my projectiles disappear.
The homing fucntion is fine, the issue is that you're not moving the transform forward. Give this a shot in the update function. Code (csharp): transform.Translate(Vector3.forward * speed * Time.deltaTime);
It's a 2D-project and "up" is indeed forward. I guess the problem may be that I have to take this in account when I LookAt(). Thanks for leading me to that realization, though! Any further help on how I solve that matter is still appreciated. Else I'll have to resort into avoiding LookAt() altogether, and do that trigonometry that I rather avoid.
Ah yea I can see the issue then since LookAt will point the z axis at the target. I'm not too familiar with using Unity to build a 2D game so unfortuantely it might be some trig for you . http://answers.unity3d.com/questions/585035/lookat-2d-equivalent-.html