Recap: Chase Camera
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 49 of 63.
Challenge
MediumWrite the chase camera for the car. The car's script is ready: the up arrow drives, left and right turn it, and its public field heading holds the way it faces, in degrees around y. heading keeps counting below 0 and past 360.
- The camera sits at the car's position plus
offset(0, 3, -6) turned around y by the camera's own yaw angle, which puts it behind the car. - That yaw starts at the car's heading and eases toward it with
Mathf.SmoothDampoversmoothTime(0.3): in a turn the camera swings round a little after the car, and always the short way. - The camera looks at the point
ahead(4) units in front of the car.
Press Play, drive in circles both ways, then Check.
Try it yourself
using UnityEngine;
public class ChaseCamera : MonoBehaviour
{
public Car car;
public Vector3 offset = new Vector3(0, 3, -6);
public float smoothTime = 0.3f;
public float ahead = 4f;
void LateUpdate()
{
}
}
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall