This repository has been archived on 2025-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
unity-cube-game/Assets/Scripts/FollowPlayer.cs

21 lines
510 B
C#

using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
public Transform Player;
public Vector3 offset;
public float smoothSpeed=0.125f;
// Update is called once per frame
void FixedUpdate()
{
Vector3 aim = Player.position + offset;
Vector3 smooth = Vector3.Lerp(transform.position, aim, smoothSpeed);
//transform.position = new Vector3(smooth.x, aim.y, aim.z);
transform.position = smooth;
transform.LookAt(Player);
}
}