Integrated custom car movements and fixed issues with follow camera behaviours.
25 lines
978 B
C#
25 lines
978 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class FollowCam : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
public Transform followPoint;
|
|
public Vector3 offset = new Vector3(0f, 5f, -10f);
|
|
public float smoothSpeed = 5f;
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (target == null) return;
|
|
|
|
Vector3 rotatedOffset = Quaternion.Euler(0, target.eulerAngles.y, 0) * offset;
|
|
Vector3 targetPositonForCam = target.position + rotatedOffset;
|
|
transform.position = Vector3.Lerp(transform.position, targetPositonForCam, smoothSpeed * Time.deltaTime);
|
|
|
|
Quaternion updatedRotation = Quaternion.LookRotation(target.position - transform.position);
|
|
updatedRotation = Quaternion.Euler(updatedRotation.eulerAngles.x, updatedRotation.eulerAngles.y, updatedRotation.eulerAngles.z);
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, updatedRotation, smoothSpeed * Time.deltaTime);
|
|
}
|
|
}
|