- Home /
 
               Question by 
               Gumemura · Aug 16, 2019 at 12:07 AM · 
                cameracamera-movement  
              
 
              Best way to make camera follow player
Guys,
Whats the best way to make camera follow player??
This is what i did. But the problem is that the camera gets a bit lag
 public class Camera_Follow_Player : MonoBehaviour
 {
     public Rigidbody2D player_follow;
     public GameObject camera_serv;
 
     void Update()
     {
         camera_serv.transform.localPosition = new Vector3(player_follow.position.x, 2.42f, -2);
     }
 }
               Comment
              
 
               
              Answer by Cornelis-de-Jager · Aug 16, 2019 at 05:47 AM
Hi @Gumemura, below is your code edited to make it smoother:
 public class Camera_Follow_Player : MonoBehaviour
 {
     public Rigidbody2D player_follow;
     public GameObject camera_serv;
     public float timeSmoothing; // default to 1f
     
     void Update()
     {
         camera_serv.transform.localPosition = Vector3.Lerp (camera_serv.transform.localPosition, new Vector3(player_follow.position.x, 2.42f, -2), timeSmoothing );
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Buttons move with the camera and I don't want that 0 Answers
Help with Texture following Camera!/How to create an effect like this in Unity 3d? 1 Answer
TPS camera in multiplayer... 2 Answers
How do I get my camera to rotate around the y=0 coordinate it's looking at? 0 Answers
Vuforia camera frustum out of view after image target is lost 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                