Camera Follow Script issues

I’m just working through Chapter 3 : Components - in the part where we create a Camera Follow script - for some reason the camera is positioning itself way down below the BobbleArena.

I checked the transform Y value of the BobbleArena, which is 13.6 - the transform Y value of space marine is 12.54, so he’s standing right on the Arena properly in the Game View.

The Camera follow script is attached to the Main Camera which is in a “CameraMount” empty container. The transform Y value of the Main Camera is 40 with a rotation of 30 so it looks down at the Space Marine.

When I run the game, the camera follow script makes the Camera zoom way under the Arena. There is only one line in the CameraFollow script :

 if (followTarget != null) {
  transform.position = Vector3.Lerp(transform.position,
    followTarget.transform.position, Time.deltaTime * moveSpeed);
}

followTarget is set to the Space Marine GameObject.

I tried replacing the third paramteter of the Lerp function with 1.0f, 0.0f and 0.01f and it make no difference to the camera behaviour. I also tried changing the Camera’s transform Y position to a much higher value and it makes no difference. The camera always zooms down below the Arena.

Anyone else have any kind of issue with this?

OK got the solution to this problem.

The cameramovement script was attached to the Main Camera rather than the CameraMount container.

For some reason, you MUST create an “Empty” gameobject to act as a container (call it CameraMount), then drag and drop the Main Camera into this. The camera movement script attaches to the parent object (CameraMount), NOT the actual Main Camera. Then everything works great.

Not sure why you can’t just skip the empty object and make the script attach directly to the main camera, but it doesn’t work. I’ll post again if I find out why.