- Home /
2D Game: When moving the camera the background glithces
Hello Unity Community!
I am working on a 2D side-scroller. I have started to work on the script for the camera. I am pretty much done with it, but I have noticed something while testing.
When I run the application, and move my player the background seems to tare. At this point in time I am using simple solid colored squares with a black outline. The outline is there so I could make sure that there was no overlapping in their placement.
When I move the player left and right I notice that I am getting an artifact from the background moving. It looks as if there is Z's. The odd part is I don't get this when I am moving up and down.
Screenshots will not show this, but here is my code.
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
Vector3 zero = Vector3.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update (Vector3 playerPosition) {
float positionDifX = Mathf.Abs (playerPosition.x - transform.position.x);
float positionDifY = Mathf.Abs (playerPosition.y - transform.position.y);
if (positionDifX > 0.5f || positionDifY > 0.5f) {
Vector3 newCameraPosition = new Vector3(playerPosition.x,playerPosition.y,-10f);
camera.transform.position = Vector3.SmoothDamp(camera.transform.position,newCameraPosition,ref zero,0.1f);
}
}
Any input will be greatly appreciated. Thanks for reading.
Your answer
Follow this Question
Related Questions
Why can't I see my objects in the scene view when adding a background image and a background camera? 1 Answer
I'm having trouble with Color.Lerp() 0 Answers
How do I create a shmup in Unity? 2 Answers
unity assetbundle scene vuforia arcamera is black 1 Answer
screen background not clearing in standalone/web player build 1 Answer