Search Unity

Camera bounds glitches

Discussion in '2D' started by Tidcy, May 30, 2020.

  1. Tidcy

    Tidcy

    Joined:
    Apr 15, 2020
    Posts:
    53
    hello, I’m a beginner and I followed a tutorial to make camera boundaries so the blue background of the unity editor doesn’t appear, and it works just fine. However I have two issues, the first one is that the camera boundaries (the coordinates) keep adjusting on their own when I open the maximized game view or change the scene window size. How do I know what size will be suitable when I build the game?

    The second issue is, right after I wrote the boundaries script the player started freaking out and shaking while moving (I can take a video of this if you need).

    Please help if you can with explanation, thx.
     
  2. sol-erides

    sol-erides

    Joined:
    Dec 8, 2018
    Posts:
    17
    Which tutorial did you follow? Posting a link (if it's free to view) as well as the code you wrote would help.
     
    Tidcy likes this.
  3. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
    A short video or even a picture and code might help. It is a little difficult to understand the issue as described. Please use the code tags if you paste code here.
     
    Tidcy likes this.
  4. Tidcy

    Tidcy

    Joined:
    Apr 15, 2020
    Posts:
    53
    Code (Csharp):
    1.  
    2. using System.Collections;
    3.  
    4. using System.Collections.Generic;
    5.  
    6. using UnityEngine;
    7.  
    8.  
    9.  
    10.  
    11. public class camerabounds : MonoBehaviour {
    12.  
    13.  
    14.     public Transform target;
    15.  
    16.     public Vector2 minipos;
    17.  
    18.     public Vector2 maxpos;
    19.  
    20.  
    21.  
    22.  
    23.  
    24.     void Start () {
    25.  
    26.  
    27.  
    28.  
    29.     }
    30.  
    31.  
    32.  
    33.  
    34. // Update is called once per frame
    35.  
    36.  
    37. void FixedUpdate () {
    38.  
    39.      
    40.  
    41. transform.position = new Vector3(Mathf.Clamp(target.position.x, minipos.x, maxpos.x),
    42.  
    43.  
    44.         Mathf.Clamp(target.position.y, minipos.y, maxpos.y),
    45.  
    46.  
    47.         transform.position.z);
    48.          
    49.  
    50.      
    51.  
    52.  
    53.  
    54.    }
    55.  
    56.  
    57.  
    58.  
    59.  
    60. }
    61.  

    Here’s the code @spryx @sol-erides
     
    Last edited: May 31, 2020
  5. sol-erides

    sol-erides

    Joined:
    Dec 8, 2018
    Posts:
    17
    The camerabounds script is placed on the main camera, correct? Also make sure that the player is not a child of the main camera, and that the main camera is not a child of the player.

    How are you setting the values of minipos and maxpos - if you are typing out the values you want in the inspector, then they shouldn't be changing as you describe and especially not when changing the size of the scene window.

    A short video of this as well as the shaking behaviour of the player would help a lot in narrowing this down.
     
    Tidcy likes this.
  6. Tidcy

    Tidcy

    Joined:
    Apr 15, 2020
    Posts:
    53
    I’m so sorry I took this long, it was a bit hard to catch on camera but here’s a link to the video

    The changing in frames while filming isn’t from the game it’s totally me

    I also filmed what happens when I change the window size