[03] Simple Follow Camera
Currently we just have the Ethan character in the scene, able to walk around the sandbox environment. The problem is that the camera doesn’t follow the player at this point, so if I move the Ethan off screen I can no longer see where he is. In order to fix this we have to make our camera follow our player, and we do this with scripting.
NO FOLLOW CAM:
Here’s the challenge:
Write CameraFollow.cs
- The script should be attached to the Camera Arm (not the Camera itself)
- The script should keep the Camera Arm at the Player’s position
- Bonus: consider using LateUpdate() instead of Update()
I’m not going to go into explanation of the code that makes this happen but essentially all you have to do is create a reference to the Player and then find the Player object by its’ “Player” tag. Now that you have a reference to the Player, you can set the transform.position of the Camera Arm object to the player.transform.position in the LateUpdate() function and you will have a follow cam.
WITH FOLLOW CAM:
So that wraps up the simple Follow Cam part, now we can follow the player as they roam all over the sandbox. Of course the camera is far from finished and I will be improving it as we go on, but this is a nice start.