Rotate light to follow player

I’ve got a spot light aiming at the player. When the player moves, I need the light to stay in the same position, but rotate so as to always be aiming at the player.

I’ve been trying to work it out for a while but haven’t found a solution, is this possible?

public class AlwaysLookAt : MonoBehaviour {

    public Transform Target;

    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
   
       
        transform.LookAt(Target);

    }
}

Just add that to your light and set Target to the player object in the editor. For future reference though, check out the transform object it has a lot of useful methods to deal with common things like that.

Thanks. This was the first thing I tried, for some reason it didn’t work but now it does.

Probably forgot to put the script on the light… :sweat_smile:

Yeah, I`ve done that enough times too :stuck_out_tongue: