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

2d camera follow not smooth (code included)

Discussion in '2D' started by simpson45711, Dec 8, 2014.

  1. simpson45711

    simpson45711

    Joined:
    Mar 16, 2013
    Posts:
    18
    I am working with a camera follow script running on a very basic/minimal scene, however no matter what I try, movement looks jerky/noticeably stutters during gameplay (even though stats shows above average framerates).

    Below is the code I am working with:

    Code (CSharp):
    1. public class CameraFollow : MonoBehaviour
    2. {
    3.  
    4.     public enum FollowAxes{ X, XY }
    5.     public FollowAxes followAxes;
    6.     public Transform target;  //player
    7.     public Vector2 offset;
    8.  
    9.     private Transform thisTransform;
    10.  
    11.     // Use this for initialization
    12.     void Start ()
    13.     {
    14.         thisTransform = transform;
    15.     }
    16.  
    17.     void FixedUpdate ()
    18.     {
    19.         if(followAxes == FollowAxes.X) thisTransform.position = new Vector3(target.position.x + offset.x, offset.y, thisTransform.position.z);
    20.         else thisTransform.position = new Vector3(target.position.x + offset.x, target.position.y + offset.y, thisTransform.position.z);
    21.     }
    22. }
    23.  
    Any advice on what I can do from here would be much appreciated.
     
  2. Ikannuna

    Ikannuna

    Joined:
    Oct 4, 2013
    Posts:
    9
    Have you tried just Update or LateUpdate?
     
  3. simpson45711

    simpson45711

    Joined:
    Mar 16, 2013
    Posts:
    18
    LateUpdate works much better, thanks.
    Did a bit more reading and seems this is better suited for camera follow scripts.