There’s a bug in my game i cannot figure out how to solve. It looks like a graphic bug and i don’t know how to fix it, i tried changing Anti-aliasing off, and all of that, still doesn’t work. I assume its the camera now, but i want help. The code and images plus a video are below.
I don’t understand it, you can see the graphic settings, and the pixel tearing. Somehow the grass doesn’t do it, but the dirt does. So far it’s layer, because I’m using unity’s Tile map system. Here’s the video.- YouTube and here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera_Controller : MonoBehaviour {
public float moveSpeed;
public GameObject camTarget;
private Vector3 Targetpos;
private static bool exists;
public BoxCollider2D bounds;
private Vector3 minBounds;
private Vector3 maxBounds;
private Camera cam;
private float halfWidth;
private float halfHeight;
private void Start()
{
DontDestroyOnLoad(transform.gameObject);
if (!exists)
{
exists = true;
DontDestroyOnLoad(transform.gameObject);
}
else
{
Destroy(gameObject);
}
moveSpeed = 5f;
camTarget = GameObject.FindGameObjectWithTag("Player");
cam = gameObject.GetComponent<Camera>();
bounds = GameObject.FindGameObjectWithTag("WorldBounderies").GetComponent<BoxCollider2D>();
minBounds = bounds.bounds.min;
maxBounds = bounds.bounds.max;
halfHeight = cam.orthographicSize;
halfWidth = halfHeight * Screen.width / Screen.height;
}
private void Update()
{
if (camTarget == null)
{
camTarget = GameObject.FindGameObjectWithTag("Player");
}
if (bounds == null)
{
bounds = GameObject.FindGameObjectWithTag("WorldBounderies").GetComponent<BoxCollider2D>();
}
Targetpos = new Vector3(camTarget.transform.position.x, camTarget.transform.position.y, 0f);
transform.position = Vector3.Lerp(transform.position, Targetpos, moveSpeed * Time.deltaTime);
float clampX = Mathf.Clamp(transform.position.x, minBounds.x + halfWidth, maxBounds.x - halfWidth);
float clampY = Mathf.Clamp(transform.position.y, minBounds.y + halfHeight, maxBounds.y - halfHeight);
transform.position = new Vector3(clampX, clampY, transform.position.z);
}
public void SetBounds(BoxCollider2D newBounds)
{
bounds = newBounds;
minBounds = bounds.bounds.min;
maxBounds = bounds.bounds.max;
}
}