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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How can I make my camera follow my character?

Discussion in '2D' started by pugsareawsome123, Feb 4, 2014.

  1. pugsareawsome123

    pugsareawsome123

    Joined:
    Dec 6, 2013
    Posts:
    1
    I am making a platforming game but i don't know how to make the camera follow my character.:confused:
     
  2. merlock18

    merlock18

    Joined:
    Dec 30, 2013
    Posts:
    28
    Drag the camera onto the player to make it a child object.
     
  3. Kurius

    Kurius

    Joined:
    Sep 29, 2013
    Posts:
    412
    Or create a script attached to the camera where the Update() method constantly adjusts the transform.position of the camera to equal the transform.position of the character.
     
  4. tonymugendi

    tonymugendi

    Joined:
    Dec 18, 2013
    Posts:
    16
    Attach this short script to your camera

    <<<<<<<<<<<<<<<<<<<SCRIPT>>>>>>>>>>>>>>


    using UnityEngine;
    using System.Collections;

    public class CameraFollow : MonoBehaviour
    {
    public Transform player;
    void Update ()
    {
    transform.position = new Vector3 (player.position.x + 9, 0, -10);
    }
    }
    <<<<<<<<<<<<<<<<THE END>>>>>>>>>>>>>>>
    Play around with the numbers according to your characters position
     
  5. majlan

    majlan

    Joined:
    Dec 30, 2013
    Posts:
    12
    Or use script included in the demo project (Tower bridge defense). It provides smoother following of the player.