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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Camera falling into void

Discussion in '2D' started by unixxer, Apr 11, 2015.

  1. unixxer

    unixxer

    Joined:
    Apr 11, 2015
    Posts:
    1
    Hi everyone,

    I'm a newbie at Unity and today's the first day I've been using it. I'm trying to make a 2D runner but for some reason the camera cannot follow the sprite/object/(whatever), but instead falls forever until I restart the game. Is there a way to make it follow my sprite and NOT infinitely fall?
     
  2. Xavior87

    Xavior87

    Joined:
    Feb 22, 2015
    Posts:
    23
    You can add the camera as a child to the sprite or you can attach this script to the Main Camera:

    public Gameobject target;

    void Update(){
    transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);
    //You can add a new variable for the z axis if you want.
    }
     
  3. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    The camera should be stationary and not fall. Have you added a RigidBody to it?