Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Please explain why this camera script doesn't work, what am I missing here?

Discussion in '2D' started by JustaDuck97, Oct 11, 2019 at 9:25 PM.

  1. JustaDuck97

    JustaDuck97

    Joined:
    Jul 31, 2019
    Posts:
    9
    Code (CSharp):
    1. public class FollowPlayer : MonoBehaviour
    2. {
    3.     //Variables
    4.     public Transform player;
    5.     public Vector3 Offset;
    6.     void fixedupdate ()
    7.  
    8.     {
    9.         transform.position = player.position + Offset;
    10.      
    11.      
    12.     }
    I'm not opposed to a lengthy explanation. I'm just trying to learn.
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,044
    void fixedupdate () should be void FixedUpdate ()

    and don't use FixedUpdate for camera move or this can be "laggy". Use Update() (or LateUpdate for the camera scripts). FixedUpdate has fixed time steps and is used for the physics. Update is calling every frame. LateUpdate is calling every frame too but at the end.
     
  3. JustaDuck97

    JustaDuck97

    Joined:
    Jul 31, 2019
    Posts:
    9
    Oh, It's always something stupidly simple with me.