The camera plays a critical role in determining how players view and interact with the game world.
Step 1: First-Person Camera
public float mouseSensitivity = 100f;
private float xRotation = 0f;
void Update() {
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
Step 2: Third-Person Camera
public Transform player;
public Vector3 offset;
void LateUpdate() {
transform.position = player.position + offset;
transform.LookAt(player);
}
Step 3: Cinematic Camera
Activity: Implement and switch between a first-person and third-person camera system.
By the end of this module, you will:
With these skills, you’ll be prepared to create stunning and functional 3D games!