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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Assistance with 2D Background Render Times

Discussion in '2D' started by markcagatandavis, Apr 7, 2018.

  1. markcagatandavis

    markcagatandavis

    Joined:
    Apr 7, 2018
    Posts:
    3
    Hi Guys,

    I'm new to Unity3D and Game development/Programming. I've been following some tutorials on how to make an RPG on Unity (gamesplusjames on YouTube). When I run my game, I can see some sort of render lag on the background when I Move/Stop moving.

    Essentially what is happening, when I move the map blurs and when I stop moving, the map is trying to catch up to itself (from what I can see). You can see an example(sorry video is downside, but you get the point): HERE

    If you look at the grass as I move it blurs (which I guess is normal since when you move motion blur does happen) but when I stop moving, you can see the background image tries to catch up to the player position.

    Here is my camera follow code in case it might be this:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraController : MonoBehaviour {
    6.  
    7.     public GameObject followTarget;
    8.     private Vector3 targetPos;
    9.     public float moveSpeed;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.        
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.         targetPos = new Vector3(followTarget.transform.position.x, followTarget.transform.position.y, transform.position.z);
    19.         transform.position = Vector3.Lerp(transform.position, targetPos, moveSpeed * Time.deltaTime);
    20.     }
    21. }

    By default does Unity render only what you see on the screen? Or do I need to create some sort of code on my camera script to render only what you see? I am guessing it could be something like this?

    Any advise, tips, and assistance would be much appreciated. :) I am using Unity 2017.3

    Thanks,
    Mark.D
     
  2. HaddicusGames

    HaddicusGames

    Joined:
    May 28, 2014
    Posts:
    28
    You could try turning off Antialiasing in your quality settings, that's what the engine uses to try and smooth out effects, which has odd effects in 2d. If that works you'll need to do that for any quality setting you support.

    Edit>Project Settings>Quality

    upload_2018-4-7_12-8-24.png
     
  3. markcagatandavis

    markcagatandavis

    Joined:
    Apr 7, 2018
    Posts:
    3
    Thanks for the fast reply, I should have said I have already done that. That resolved the "ghosting" of the player when he moves, but the background still does the same thing.
     
  4. markcagatandavis

    markcagatandavis

    Joined:
    Apr 7, 2018
    Posts:
    3
    I did some further testing and if I child the "Main Camera" to my player, this issue doesn't occur. So this must have something to do with my camera controller script...

    Testing with Main Camera Child
    upload_2018-4-8_10-5-30.png

    Code (CSharp):
    1. public class PlayerController : MonoBehaviour {
    2.  
    3.     public float moveSpeed;
    4.  
    5.     private Animator anim;
    6.     private bool playerMoving;
    7.     private Vector2 lastMove;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.         anim = GetComponent<Animator>();
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void Update () {
    16.  
    17.         playerMoving = false;
    18.  
    19.         if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
    20.         {
    21.             transform.Translate(new Vector3 (Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime,0f,0f));
    22.             playerMoving = true;
    23.             lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
    24.         }
    25.  
    26.         if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
    27.         {
    28.             transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
    29.             playerMoving = true;
    30.             lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
    31.         }
    32.  
    33.         anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
    34.         anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
    35.         anim.SetBool("PlayerMoving", playerMoving);
    36.         anim.SetFloat("LastMoveX", lastMove.x);
    37.         anim.SetFloat("LastMoveY", lastMove.y);
    38.     }
    39. }