Skip to content

Instantly share code, notes, and snippets.

@VeggieVampire
Created August 18, 2019 08:44
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 VeggieVampire/3e2fbb85d08f83a2c63fb7240370f17e to your computer and use it in GitHub Desktop.
Save VeggieVampire/3e2fbb85d08f83a2c63fb7240370f17e to your computer and use it in GitHub Desktop.
Unity 3D Spotlight Fallow controller. Slow the speed down to have the light fall behind. "Lerp Spotlight "
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpotlightController : MonoBehaviour {
private Vector3 targetPos;
public float moveSpeed = 10f;
public GameObject followTarget;
public float Xoffset = 0f;
public float Yoffset = 5f;
public float Zoffset = -1f;
// Use this for initialization
void Start () {
if (!followTarget) {
followTarget = GameObject.FindGameObjectWithTag ("Player");
}
}
// Update is called once per frame
void Update () {
}
void FixedUpdate () {
if (!followTarget) {
followTarget = GameObject.FindGameObjectWithTag ("Player");
} else if (followTarget) {
targetPos = new Vector3 (followTarget.transform.position.x+Xoffset, followTarget.transform.position.y+Yoffset, followTarget.transform.position.z+Zoffset);
}
transform.position = Vector3.Lerp(
transform.position, //Position Currently at //FROM
targetPos, //Position Want to be at //TO
moveSpeed * Time.deltaTime ); // At what speed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment