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

Camera follow player but stop at map end

Discussion in 'Scripting' started by blekkh, Apr 20, 2020.

  1. blekkh

    blekkh

    Joined:
    Feb 14, 2019
    Posts:
    19
    So I want that my camera follows the player but only on the y axis, this works fine as it should, but now I want that the camera just stops if it is at the top or bottom of the map

    I tried this:

    if(transform.position.y <= 3 || transform.position.y >= -3 ){ transform.position = new Vector3(MapMittlePosition.position.x, Player.transform.position.y, transform.position.z);
    }


    I actually dont know why this doesnt work, so now I need help, thanks for every answer
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Your condition reads:

    If position smaller equals 3 OR larger equals -3 then...

    Which is always true. Any given number is either bigger than -3 or smaller than 3. This is true for all positive and negative numbers. You wanted to put an 'AND' there instead. Then it would limit the numbers for which the statement is true to the range of -3 to +3.

    Also, please use code tags in the future.
     
  3. blekkh

    blekkh

    Joined:
    Feb 14, 2019
    Posts:
    19
    ooooh thanks so much :D