Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved 2.6.2 Free Look - Can i make the whole rig delayed in following the character

Discussion in 'Cinemachine' started by lucaskargreen, Sep 11, 2020.

  1. lucaskargreen

    lucaskargreen

    Joined:
    Sep 10, 2020
    Posts:
    21
    I'm trying to make a 3D TPP cube game with a lot of verticality. I can only get the camera to tilt or lag behind within the rig. any way I can make the whole rig lag behind?

    I'm taking inspiration from Cube Worlds camera movement
     
  2. lucaskargreen

    lucaskargreen

    Joined:
    Sep 10, 2020
    Posts:
    21
    I solved it by adding an empty GameObject that follows the player with lag and having the camera rig follow the GameObject.

    Code for the empty GameObject

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CameraFollowTarget : MonoBehaviour
    4. {
    5.     public Transform target;
    6.     public float smootSpeed = 25f;
    7.  
    8.     private Vector3 velocity = Vector3.zero;
    9.  
    10.     void LateUpdate()
    11.     {
    12.         Vector3 desiredPostion = target.position;
    13.         Vector3 smoothedPosition = Vector3.SmoothDamp (transform.position, desiredPostion, ref velocity, smootSpeed*Time.deltaTime);
    14.         transform.position = new Vector3(desiredPostion.x, smoothedPosition.y, desiredPostion.z);
    15.  
    16.     }
    17. }