Search Unity

Bug My camera follow works fine in scene view, but not in game view.

Discussion in 'Editor & General Support' started by Ch267, Oct 19, 2020.

  1. Ch267

    Ch267

    Joined:
    Sep 16, 2019
    Posts:
    55
    The camera follows the player perfectly in scene view and the position updates in the inspector as the player moves. But in game view, I can't move my player.
    Here's my CameraFollow script for reference:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class CameraFollow : MonoBehaviour
    5. {
    6.     public Transform player;
    7.     public float smoothSpeed = 0.125f;
    8.     public Vector3 offset;
    9.  
    10.     private void LateUpdate()
    11.     {
    12.         Vector3 desiredPosition =this.gameObject.transform.position = player.position + offset;
    13.         Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
    14.         transform.position = smoothedPosition;
    15.     }
    16. }
    And here's a video if you want to see the editor side of the error:
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You have a completely solid background, and the camera is moving with the player. So when the player moves (and the camera with it), how do you expect to see it in the Game view? For a camera like this, you need to have a background in which you can actually notice the player moving in front of. Or put other objects in the scene so you can see the player moving relatively to those objects.
     
    Ch267 likes this.
  3. Ch267

    Ch267

    Joined:
    Sep 16, 2019
    Posts:
    55
    Can you elaborate, please?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm not sure how to be more clear. When humans perceive motion it is because the object is moving relative to something else. You've got nothing else in the scene, and you're moving the camera in lock step with the player. So it is not possible to perceive its motion. Put some other stuff in the scene and retest.

    Just think about this for a moment. You have a completely solid gray scene. The only thing visible is the player object. You then move both the player and camera objects 5 units to the right. What is that going to look like with your completely solid gray background and nothing else? It will look exactly like the object hasn't moved at all even though it has moved.
     
    Last edited: Oct 20, 2020
    Ch267 likes this.
  5. Ch267

    Ch267

    Joined:
    Sep 16, 2019
    Posts:
    55
    The only error was in my brain.
     
    Joe-Censored likes this.