rabidus-test/Assets/Dreamteck/Splines/Examples/Junctions/Scripts/TrainCamera.cs

24 lines
622 B
C#
Raw Normal View History

2023-07-24 16:38:13 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrainCamera : MonoBehaviour
{
public Transform target;
public Vector3 offset;
public float speed = 1f;
Transform trs;
private void Awake()
{
trs = transform;
}
void LateUpdate()
{
Vector3 targetPos = target.position + target.right * offset.x + target.up * offset.y + target.forward * offset.z;
Quaternion rotation = Quaternion.LookRotation(targetPos - trs.position);
trs.rotation = Quaternion.Slerp(trs.rotation, rotation, Time.deltaTime * speed);
}
}