I’m working with Unity for the first time ever for school, and I’m making a Roll a Ball project. I’m trying to get the spotlight to follow the Player, and used the same script I used to make the camera follow the player but changed CameraController to LightController, but I didn’t like how to light followed the player instantly. I ended up changing my code to this:
using UnityEngine;
using System.Collections;
public class LightController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
public float delay = 0.5f;
public float followNow;
void Start()
{
followNow = Time.time + delay;
offset = transform.position;
}
void LateUpdate ()
{
if (Time.time > followNow) {
if (player != null) {
transform.position = player.transform.position + offset;
}
followNow += delay;
}
}
}
And this way, the light waits 0.5 frames to center on the player, but it’s erratic and not smooth at all. It practically teleports to the player’s new location after 0.5f, but I want to know how to make it lag behind like it is, and smoothly make it’s way to the player to center on it if it comes to a stop. Can somebody help me figure this out?
Also, I don’t know if this is useful info, but I made the spotlight a rigid body and made it kinematic so it would stop shrinking into the player after every frame.