Question by
Natfran · Jul 06, 2017 at 09:02 PM ·
transform.lookat
GameObject does not set transform
So basically I am trying to create a homing missile, I am using transform.LookAt(target), but my player instantiates the missile, the missile does not look at the target. It only works if the missile is already in the scene when the game is started.
This is the code: using UnityEngine; using System.Collections;
public class Missile : MonoBehaviour {
public float lifeTime = 15;
public GameObject impactEffect;
public Transform target;
// Use this for initialization
void Start () {
Destroy (gameObject, lifeTime);
}
// Update is called once per frame
void Update () {
transform.LookAt (target);
transform.Translate (Vector3.forward * 100 * Time.deltaTime);
}
Comment
Your answer
Follow this Question
Related Questions
using LookAt(), transform.forward but move only in X axis 0 Answers
Optimization question: facing rotation 0 Answers
LookAt doesnt work 1 Answer
Make object always face and rotate to another object 1 Answer
transform.lookAt not working as intended 0 Answers