Check out a free preview of the full Game Development with Unity for Web Developers course

The "Camera Movement Exercise" Lesson is part of the full, Game Development with Unity for Web Developers course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to create a script component called CameraMovement that attaches to the camera GameObject and moves the camera gently to frame the action.

Preview
Close

Transcript from the "Camera Movement Exercise" Lesson

[00:00:00]
>> So our game doesn't really have any camera movement right now, it's a static camera. It would be a lot more interesting and dynamic if the camera was actually moving around and attempting to follow some of the action. So using what we've learned so far, I want you to try to stretch a little bit and create a script component called CameraMovement that attaches to the camera GameObject and moves the camera gently to frame the action.

[00:00:34]
So I've got a couple hints here, and I'll give you one more. So the first hint is you should use Vector3.Lerp() inside of Update(), not fixed update, to move the camera's position every frame. The reason you wanna use Update() is because it's the camera, it's was rendering things every frame.

[00:00:55]
So you do actually want it to move at the frame rate to capture the action. The second hint is, you'll probably want to calculate the camera's position by offsetting it by some distance from the board. Because if you just have a target, it's not going to be offset correctly, I guess.

[00:01:24]
So yeah, so you need to set the movement target to the target's position plus some X, Z offset. And then you need to linearly interpolate the position from the current position to the target. And I said I had one more hint for you, and that is that you won't actually need to access the camera component to do this.

[00:01:46]
You should just be able to do this with the game object's transform.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now