- Home /
 
               Question by 
               DrSquirrelBoy12 · Feb 17, 2014 at 09:41 PM · 
                cameracamera followcamera controls  
              
 
              Making Camera Follow Object in only 1 direction 2D
I have a player object that I need to be followed by the camera in the y direction. I have a gravity force acting on the game object and I need the camera to stay with the object in the y direction without moving the camera in the x direction when I move the character left or right. Thank you in advance!
               Comment
              
 
               
              Answer by robertbu · Feb 17, 2014 at 09:42 PM
Initialize 'target' to your player in the inspector. Note the movement is done in 'LateUpdate()' rather than Update().
 var target : Transform;
 
 function LateUpdate() {
    camera.main.transform.position.y = target.y;  
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                