Search Unity

HELP ME T-T 2D Top/Down Camera Perspective Control

Discussion in '2D' started by pasquali2313, Jul 4, 2018.

  1. pasquali2313

    pasquali2313

    Joined:
    Jul 4, 2018
    Posts:
    3
    OK so I need help -.-' I am very new to this and I only really know the basics of programming in Java and C++ but I am trying to create a very basic 2D Top/Down game in unity (of course using C#). I have the player movement, I have the maps, I can get the camera to follow the player (without making the player the parent to the camera) using a script.

    I should add that this game is pixel art as well. I removed anti-aliasing and used pixel snap to make sure there aren't any random lines poping up.

    However, even with damping/smoothing the camera still Jitters to some extent and don't know how to prevent this.

    Also, since the camera follows the player it lags behind the player and not directly on him. so when he is moving left, the left side of the screen is the smallest portion, and therefore you cant see very much ahead of him. Increasing the Cam speed does make it so that it can keep up with the player but it ends up adding more jitteryness.

    I would like and RPG-like feel to this game and wanted to get the camera to surpass the player by a couple of units to make it so that the player can see ahead of him (in any direction he chooses).

    Since it is a top down, I shouldn't have used the term "left" but West. As the player can go; North, North-East, East, South-East, South, South-West, West, North-West.

    (edit) The code I have is simple and I haven't added smoothing to this one, so the camera just clips a certain distance from the player (ahead) also, the random lines have shown back up now and I don't know why, but if i play it in maximized the lines disappear. But the Jitteryness is still visible PLZ HELP!!

    Code (CSharp):
    1. public class CameraBehavior : MonoBehaviour {
    2.  
    3.     public GameObject target;
    4.  
    5.     private Vector3 offset = new Vector3(0f, 0f, -11f);
    6.     private Vector3 moveOffset;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.         transform.position = target.transform.position + offset;
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void FixedUpdate () {
    15.  
    16.         moveOffset = new Vector3(Input.GetAxisRaw("Horizontal") * 1.1f, Input.GetAxisRaw("Vertical") * 1.1f, 0f);
    17.  
    18.         transform.position = target.transform.position + moveOffset + offset;
    19.     }
    20. }
    21.  
     
    Last edited: Jul 4, 2018
  2. Raali_Oloth

    Raali_Oloth

    Joined:
    Jul 29, 2013
    Posts:
    22
    why FixedUpdate for camera?
    if your player moves in Update it can create Jitteryness
     
    Thorlar likes this.
  3. Thorlar

    Thorlar

    Joined:
    Oct 7, 2017
    Posts:
    28
    I don't know much about pixel snapping and how it is related with Camera, but I would suggest to use LateUpdate() for Camera instead of FixedUpdate()

    I think for Camera you need smoothing or damping, although idk if this is the issue here since not much is known from your post

    What random lines? Could you explain more?

    But yeah, especially for Camera, there are sooo many tutorials on youtube :p
     
    Last edited: Jul 5, 2018
  4. pasquali2313

    pasquali2313

    Joined:
    Jul 4, 2018
    Posts:
    3
    Ok so I did fix some stuff on my cam. I was able to get the cam to move ahead of the player. I am using a Vector3.Lerp and pixel snap. I have tried late update, fixedupdate, update but none of them fixed the issue of jitteryness. Every now and then (3secs) it will jitter. also The pixels seem to me changing sizes when i move around?
     
  5. pasquali2313

    pasquali2313

    Joined:
    Jul 4, 2018
    Posts:
    3
    the image provide a look at what i mean. All the black pixels are one pixel thick. but they are nearly all different sizes (this may be causing the jitteryness, but i think this is unrelated)
     

    Attached Files:

  6. Thorlar

    Thorlar

    Joined:
    Oct 7, 2017
    Posts:
    28
    jitteriness may be related to pixel perfect.

    If you want to confirm it, use the same camera, on a new project and test it out in a non-pixel perfect project to confirm it :p

    However, if the jitteriness is related to the time (every 3 seconds) I doubt it's pixel perfect but something else.
    (Example: if you are moving at a stable speed with a normal/blank background, and it jitters based on time, exclusively... it's probably something else)

    Aside of that, I don't have any other ideas on what can be wrong (especially considering ur using Lerp)

    I hope you find the solution you are looking for :D (since sadly, I am not really helpful on pixel perfect or cameras)
     
unityunity