Skip to content

Instantly share code, notes, and snippets.

@igilham
Last active October 8, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igilham/0446c48e4e54b9708e7180e83d6e0448 to your computer and use it in GitHub Desktop.
Save igilham/0446c48e4e54b9708e7180e83d6e0448 to your computer and use it in GitHub Desktop.
Really basic Unity camera script to follow the player object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Simple camera follow system
public class CameraFollow : MonoBehaviour
{
// The target to follow
public Transform Target;
// Position offset from target
public Vector3 Offset;
// How far to look ahead of the target
public float LookAheadOffset;
void Update()
{
var camCentre = Target.position + (Target.forward * LookAheadOffset);
transform.position = camCentre + Offset;
transform.LookAt(camCentre);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment