Last active
October 8, 2020 16:11
-
-
Save igilham/0446c48e4e54b9708e7180e83d6e0448 to your computer and use it in GitHub Desktop.
Really basic Unity camera script to follow the player object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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