- Home /
Camera / Graphic bug with 2D Sprites [Please help me solve this]
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. https://www.youtube.com/watch?v=_Xo7Re-ltz8 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;
}
}
Answer by eses · Aug 30, 2018 at 07:20 AM
Hi @memeinaction
For starters, take maybe four tiles (with biggest difference in their color palette), then add 2-8 pixels of padding around each tile graphic.
Then import these to Unity, create a temporary test map out of them.
Then see if you still get color bleed.
It's most likely from neighbor tiles in (texture)map / source image itself, but there might be other reasons for this too.
Here is one tutorial explaining the basic reason: https://youtu.be/QW53YIjhQsA
Answer by Runalotski · Aug 18, 2018 at 02:00 PM
Hi,
On the png file for your dirt texture. If you click on that you should get import settings.
Try setting the following.
Bit maps: off Filter Mode: Point
Could you also send a screen shot of these settings?
yeah, sorry for the response, i can take a screenshot of my settings. Although i do have bit maps off and Filter $$anonymous$$ode to point, doesn't do anything.
What did you export this picture as?
If you have any compression the green pixels next to the dirt may bleed into it perhaps? If you use GI$$anonymous$$P there is an option that you can set to 0 and then set no compression on in unity.
.png i think it was on Nearest Neighbor on photoshop exporting
Answer by Robotic_Soul · Aug 29, 2018 at 07:36 AM
I don't have a solution for you, but I can help you understand how to debug this issue a bit. Try to create a scene file which has the minimum number of things loaded needed to reproduce the error. This can help give you insight, and better make your case for bugs. It can also give you a safe place to explore the issue. You need to be able to change things without being afraid you'll mess up your game. Good Luck
@Robotic_Soul - a comment - isn't your answer more like a comment too?
Answer by sushillakra21 · Aug 29, 2018 at 08:29 AM
I am not sure but I saw something like this when I was creating a endless runner and repeated same image, because both images were joined very closely I could see gaps, I overlapped those images. Just trying to help may not be relevant.