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

Limit camera movement

Discussion in '2D' started by mondeon, Jun 2, 2015.

  1. mondeon

    mondeon

    Joined:
    May 29, 2015
    Posts:
    46
    Hello Unity-Community!

    I am working on a 2D game (beginner level) and I have the following problem:

    The camera is following the player. When the camera reaches end of map it shouldn't go beyond borders of map (but the player is allowed to reach until the border). When the player go then away from the borders the camera should continue following. Also I want to deactivate the camera movement when the player jumps (until the end of the jump animation).

    I don't know how to solve this problem or where to start, any ideas are much appreciated!
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I'll give you a general - non code - example.

    Set up a collider for the camera at the end of the level. When the camera collides with this collider change the parent of the camera from the player to an empty game object - or to itself.
    If the player moves away a specified distance from the end of the level - re-parent the camera back to the player.

    About jump - do you want the camera to follow the player on X but not on Y. You could do this in code I'm sure. Just don't inherit the Y motion of the player when he is jumping.

    Those will probably get you moving in the right direction.
    A programmer dev may have better processes to do these. :)
     
  3. Gardes

    Gardes

    Joined:
    Apr 7, 2015
    Posts:
    46


    (This tutorial is not made by me)
     
    ascemek and theANMATOR2b like this.
  4. mondeon

    mondeon

    Joined:
    May 29, 2015
    Posts:
    46
    All right, thanks to both of you, that gave me some ideas! working on the implementation now..