JeCodeLeSoir

Camera

Jul 19th, 2024
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayerCamera : MonoBehaviour
  4. {
  5.     Transform tx;
  6.     [SerializeField] Transform tx_player;
  7.  
  8.     [SerializeField] Vector3 offset = new Vector3(0, 1, 0);
  9.     [SerializeField] float smoothTime = 0.8f;
  10.  
  11.     private Vector3 Velocity;
  12.     private Vector3 offsetsubstract;
  13.     private Vector3 current;
  14.  
  15.     void Start()
  16.     => tx = transform;
  17.      
  18.     void Update()
  19.     {
  20.         current = tx.position;
  21.         current -= offsetsubstract;
  22.         tx.position = offset + Vector3.
  23.             SmoothDamp(current, tx_player.position, ref Velocity, smoothTime);
  24.         offsetsubstract = offset;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment