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 Movement Problem.

Discussion in '2D' started by LucaBGT, Feb 20, 2015.

  1. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    I am planning to do a 2d-Point and Click Adventure. It should take place in closed rooms. I have got a camera controller, but this one follows the player wherever it goes. It's especially bad because when the player touches the rooms end, the camera continues to go further, so you can see untextured space. Could someone help me with this?
    Thanks!
    PS: The Camera should stop moving at the surrounding of the background, But the player should be able to touch the walls. Wrong camera.png
     
  2. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    depending on how you have done your levels, you could use Mathf.Clamp() to limit the camera movement in the horizontal if you know the exact limitations.

    or have some boundary colliders, so they dont move past the outer boundaries of the level width.

    ie at the end of the levels put boundary collider objects, and set the camera so its clamped between them.
     
    Last edited: Feb 21, 2015
  3. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    Thanks for your answer!
    But, to my own shame, I'm a Unity beginner, so I don't really know how to do that.
    I got some camera scripts from the "Sample Assets Beta", but I'm really confused.
    It would be nice if you could explain a little more. I could post the code here too, so you could
    tell me what exactly to edit. It would be really nice!
     
  4. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning Luca,

    if you have a look at the Live Training Session Adam done with the Angy Birds clone, he has a camera tracker script that does exactly what I think your after in a 2D environment.

    watch between 3 mins and 10.
     
  5. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    Wow, awesome!
    I will see the tutorial now, thanks for sending it!
     
  6. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    It worked!

    Unity Forum 1.png Unity Forum 2.png
     
    OboShape likes this.
  7. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    nice one :)