how LookAt function work?

Heading

I have a camera that I can move with WASD keys ingame and I have a spotlight that follow camera with a script(attached to spotlight only), but when I move camera(change position) the spotlight change his rotation instead position :frowning:

Script (C#):

public class Follow : MonoBehaviour {
	
	public Transform target;
	
	// Update is called once per frame
	void Update () {
		transform.LookAt(target);
	}
}

I am following this tutorial(page 4 exactly): http://download.unity3d.com/support/Tutorials/2%20-%20Scripting%20Tutorial.pdf

The LookAt function rotates the GameObject’s transform, rather than moving it (i.e the “Looking At” naming).

There are two things you could do, the easiest being, make the spotlight attached to the same GameObject as the Camera. The light will then follow automatically!

The other way is a bit more granular control, albeit a bit more difficult to do when beginning with 3d programming, is to adjust the Transform of the spotlight manually by in addition to what you have, add a line that move the position as well as it’s rotation like so:

void Update () {
       transform.LookAt(target); // still wrong since this points the light at the camera; I assume you want it pointing in the cameras forward direction??? 


       transform.Position = new Vector3(target.position.x, target.position.y, target.position.z);
}

Another idea too, is that you could Lerp ([documentation])1 the distance if you wanted the light to not feel so tightly bound to the camera movements.