You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
727 B
C#
24 lines
727 B
C#
1 month ago
|
using UnityEngine;
|
||
|
|
||
|
public class SideCameraFollow : MonoBehaviour
|
||
|
{
|
||
|
public Transform target; // player (runner)
|
||
|
public Vector3 offset = new Vector3(-5f, 2f, 0f); // side view offset
|
||
|
public float followSmoothTime = 0.2f;
|
||
|
|
||
|
public Vector3 rotationOffset = new Vector3(0f, 90f, 0f); // new!
|
||
|
|
||
|
private Vector3 velocity;
|
||
|
|
||
|
void LateUpdate()
|
||
|
{
|
||
|
if (target == null) return;
|
||
|
|
||
|
// Follow player's Z and Y, offset on X
|
||
|
Vector3 desiredPos = target.position + offset;
|
||
|
transform.position = Vector3.SmoothDamp(transform.position, desiredPos, ref velocity, followSmoothTime);
|
||
|
|
||
|
// Apply custom rotation offset
|
||
|
transform.rotation = Quaternion.Euler(rotationOffset);
|
||
|
}
|
||
|
}
|