I’ll do my best to explain this. The usage is a bit unconventional and I’ve had a hard time getting the purpose across to others. I’m trying to get an object to aim at the player character using a spotlight with a slight offset. This object is a visual representation of the Main Camera and should not affect its behavior or movement.
Imagine the Lakitu camera guy from Mario Kart if that helps, but with a spot light attached.
With that explanation in mind, this is a script I thought fit pretty well in principle, but it doesn’t aim at the player like it’s supposed to. Independently maybe it would work just fine, but I’d like to figure out what’s wrong here.
public class LightTarget : MonoBehaviour
{
public Transform target;
public float speed = 5;
private void update()
{
Vector3 direction = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(direction);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, speed * Time.deltaTime);
}
}
Here’s a screenshot of how I’ve got things setup.
I’ve got an Empty Object (named Main Camera), Systems (the camera and other various components), and then the Drone (a simple sphere) with the Light Target script attached to it. Child to the Drone is the standard Spot Light component and a basic Cylinder to determine if the Sphere and Spot Light are rotating or not.
Any help or suggestions would be greatly appreciated.
