Created
August 18, 2019 08:44
-
-
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 "
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; | |
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