Added camera tracking to handle vertical level

for my level2 I thought I’d make it vertical - then found I had to pull the camera back insanely far to frame it all. Initially I parented the camera to an empty gameobject, then scripted the parent object to match the rocket’s transform on the update message. However, I found this tutorial on getting a camera to follow a game object using Lerp, which smooths it all out :grinning:

Smooth Camera Follow in Unity - Tutorial

3 Likes

Oh, and if it’s useful, this is the script I added to the camera GameObject:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CamTrack : MonoBehaviour {
    [SerializeField] Transform targetGameObject;
    //[SerializeField] float trackXFactor = 1f;
    // [SerializeField] float trackYFactor = 1f;
    // [SerializeField] float trackZFactor = 1f;
    // Vector3 startingPos;
    [SerializeField] float smoothSpeed = 0.125f;
    [SerializeField] Vector3 offset;


	void FixedUpdate ()
    {
        Vector3 desiredPosition = targetGameObject.position + offset;
        Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
        transform.position = smoothedPosition;
    }
}

Privacy & Terms