Skip to main content
Title should describe what the question is, not your last update.
Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Added another example of How to create a camera not lerping, but moving awaythat combines both forced movement and smooth player following

added 208 characters in body; edited title
Source Link

Camera follow player with Lerp and Added another example of camera not lerping, but moving away after idle

Camera with Lerp, but not moving away from the player

Camera Lerps after moving, but it doesn't move away from the player

Camera moving away, but not following player with lerp

enter image description here

Camera follow player with Lerp and moving away after idle

Camera Lerps after moving, but it doesn't move away from the player

Added another example of camera not lerping, but moving away

Camera with Lerp, but not moving away from the player

Camera Lerps after moving, but it doesn't move away from the player

Camera moving away, but not following player with lerp

enter image description here

Added a tiny demo of my issue, and clarified a little bit of more information
Source Link

Example

Camera Lerps after moving, but it doesn't move away from the player

Code

CameraController.cs

using System.Collections; using System.Collections.Generic; using UnityEngine; /* ** Camera following player (Smoothing and angle): https://youtu.be/4HpC--2iowE ** Maximo: https://www.youtube.com/watch?v=bXNFxQpp2qk&ab_channel=iHeartGameDev ** Moving character relative to camera: https://forum.unity.com/threads/moving-character-relative-to-camera.383086/ ** Camera follow v2: https://youtu.be/Jpqt2gRHXtc?list=PLq_nO-RwB516fNlRBce0GbtJSfysAjOgU */ public class CameraController : MonoBehaviour { public GameObject player; public PlayerControl playerControlScript; private Vector3 newCameraPos; public bool stillIdle;   void Start() { stillIdle = false; PlayerControl playerControlScript = GetComponent<PlayerControl>(); } void LateUpdate() { player = GameObject.FindGameObjectWithTag("Player"); if (playerControlScript.GetfirstInput()) //True { stillIdle = true; newCameraPos = Vector3.Lerp(transform.position, playerControlScript.transform.position, Time.deltaTime); transform.position = new Vector3(newCameraPos.x, 1, newCameraPos.z); } if (stillIdle) transform.position = new Vector3(transform.position.x + 0.69f * Time.deltaTime, transform.position.y, transform.position.z); //Moving camera away effect } } 

PlayerControl.cs

public class PlayerControl : MonoBehaviour { bool firstInput; Vector3 startPos; Vector3 endPos; public bool GetfirstInput() //I was learning how to have a Get function while my member was private from another script file { return firstInput; } void Update() { if (Input.GetButtonDown("up") || Input.GetButtonDown("left") || Input.GetButtonDown("right") || Input.GetButtonDown("down")) { //if game starts { //Other variables being initialized here firstInput = true; } }    } } 

Hierarchy/Inspector

Main Camera

enter image description here

Player Object

enter image description here

Code

using System.Collections; using System.Collections.Generic; using UnityEngine; /* ** Camera following player (Smoothing and angle): https://youtu.be/4HpC--2iowE ** Maximo: https://www.youtube.com/watch?v=bXNFxQpp2qk&ab_channel=iHeartGameDev ** Moving character relative to camera: https://forum.unity.com/threads/moving-character-relative-to-camera.383086/ ** Camera follow v2: https://youtu.be/Jpqt2gRHXtc?list=PLq_nO-RwB516fNlRBce0GbtJSfysAjOgU */ public class CameraController : MonoBehaviour { public GameObject player; public PlayerControl playerControlScript; private Vector3 newCameraPos; public bool stillIdle; void Start() { stillIdle = false; PlayerControl playerControlScript = GetComponent<PlayerControl>(); } void LateUpdate() { player = GameObject.FindGameObjectWithTag("Player"); if (playerControlScript.GetfirstInput()) //True { stillIdle = true; newCameraPos = Vector3.Lerp(transform.position, playerControlScript.transform.position, Time.deltaTime); transform.position = new Vector3(newCameraPos.x, 1, newCameraPos.z); } if (stillIdle) transform.position = new Vector3(transform.position.x + 0.69f * Time.deltaTime, transform.position.y, transform.position.z); //Moving camera away effect } } 

Example

Camera Lerps after moving, but it doesn't move away from the player

Code

CameraController.cs

using System.Collections; using System.Collections.Generic; using UnityEngine; /* ** Camera following player (Smoothing and angle): https://youtu.be/4HpC--2iowE ** Maximo: https://www.youtube.com/watch?v=bXNFxQpp2qk&ab_channel=iHeartGameDev ** Moving character relative to camera: https://forum.unity.com/threads/moving-character-relative-to-camera.383086/ ** Camera follow v2: https://youtu.be/Jpqt2gRHXtc?list=PLq_nO-RwB516fNlRBce0GbtJSfysAjOgU */ public class CameraController : MonoBehaviour { public GameObject player; public PlayerControl playerControlScript; private Vector3 newCameraPos; public bool stillIdle;   void Start() { stillIdle = false; PlayerControl playerControlScript = GetComponent<PlayerControl>(); } void LateUpdate() { player = GameObject.FindGameObjectWithTag("Player"); if (playerControlScript.GetfirstInput()) //True { stillIdle = true; newCameraPos = Vector3.Lerp(transform.position, playerControlScript.transform.position, Time.deltaTime); transform.position = new Vector3(newCameraPos.x, 1, newCameraPos.z); } if (stillIdle) transform.position = new Vector3(transform.position.x + 0.69f * Time.deltaTime, transform.position.y, transform.position.z); //Moving camera away effect } } 

PlayerControl.cs

public class PlayerControl : MonoBehaviour { bool firstInput; Vector3 startPos; Vector3 endPos; public bool GetfirstInput() //I was learning how to have a Get function while my member was private from another script file { return firstInput; } void Update() { if (Input.GetButtonDown("up") || Input.GetButtonDown("left") || Input.GetButtonDown("right") || Input.GetButtonDown("down")) { //if game starts { //Other variables being initialized here firstInput = true; } }    } } 

Hierarchy/Inspector

Main Camera

enter image description here

Player Object

enter image description here

deleted 61 characters in body
Source Link
Loading
Source Link
Loading