- Home /
 
               Question by 
               shayaans · Sep 20, 2015 at 07:18 PM · 
                cameraplayercamera followcamera viewport  
              
 
              Camera following player in Tutorial Demo (Roll A Ball)
I finished the tutorial. I wanted to change the game so that the camera is always behind the player
Gears Of War Metal Gear Solid any 3rd person game
My CameraController looks like
 using UnityEngine;
 using System.Collections;
 
 public class CameraController : MonoBehaviour {
     public GameObject player;
     private Vector3 offset;
     // Use this for initialization
     void Start () {
         offset = transform.position - player.transform.position;
     
     }
     
     // Update is called once per frame
     void LateUpdate () {
         transform.position = player.transform.position + offset;
     }
 }
My PlayerController looks like
 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
     
     public float speed;    
     public Text countText;
     public Text winText;
     private Rigidbody rb;
     private int score;
     
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
         score = 0;
         setCountText ();
         winText.text = "";
     }
 
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
         
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
         
         rb.AddForce (movement * speed);
     }
 
     void OnTriggerEnter(Collider other) 
     {
         if (other.gameObject.CompareTag ("Pick Up"))
         {
             other.gameObject.SetActive (false);
             score++;
             setCountText();
         }
     }
 
     void setCountText()
     {
         countText.text = "Score: " + score.ToString ();
         if (score >= 9) {
             winText.text = "You Win!";
         }
     }
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Dedicated Cameras? 1 Answer
How do I make the camera zoom out, relative to my players size? 2 Answers
Camera and Player position 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                