- Home /
Lines between Tiles
I have a tile-based games. Each tile is a game object with a sprite renderer attached. Tile locations are generated through code. Their x/y coordinates are whole numbers. I have a camera that follows the player using a smooth damp.
This is my player follow script (attached to camera) - The behavior I want is correct, minus one problem (see image below):
public class FollowPlayer : MonoBehaviour
{
// Use this for initialization
private Transform player;
private Vector3 velocity = Vector3.zero;
private Vector3 target = Vector3.zero;
private bool zoomIn = true;
void Start()
{
player = null;
}
// Update is called once per frame
void Update()
{
if (player == null)
{
var p = GameObject.FindWithTag("Player");
if (p != null)
{
player = p.transform;
}
}
if(player != null)
{
if (Input.GetKeyDown(KeyCode.Z))
{
zoomIn = !zoomIn;
}
if (zoomIn)
camera.orthographicSize = 5.0f;
else
camera.orthographicSize = 10.0f;
target = new Vector3(player.transform.position.x, player.transform.position.y + (zoomIn ? 2.0f : 8.0f), camera.transform.position.z);
transform.position = Vector3.SmoothDamp(transform.position, target, ref velocity, 0.3f);
}
}
}
My sprite images are 32x32 PNGs. I auto-sliced them, but they take up the entire width of the image, so their slices are correct (coming out to 32x32 sprites). The pixels to units is set to 32, with an orthogonal camera size of 5. Filter Mode set to point, and format set to true color.
Any ideas?
Once the camera stops moving completely, I get this:
Looks like setting my pixels to units to 31 did the trick, as suggested in another answer with a similar problem. I'm still a bit confused as to why I can't use 32 pixels to one unit, though.