I’ve been looking around on google, forums and where ever I can get any information and can’t seem to find any solutions or ideas out there to solve the problem.
I’ve got my camera following me on my pixel art game, however I want to give it a slight delay behind the character. The problem with giving it a slight delay is that pixel art sprites with a ‘Point’ filter give a weird ripple/warping effect simply because it’s not pixel perfect.
I have also set my sprites to use a pixel unit of 100, I’ve read some people using a pixel unit of 1, but I’m not sure what the good’s and bad’s are of this.
So I went ahead and tried using this code over here Script for unity to create a pixel locked orthogonal camera · GitHub which locks the camera to pixels and actually reduces the pixel ripple/warping effect however because my character moves with a 2D Rigidbody ( which isn’t pixel perfect ) it ends up making the character look like it’s jiggling as it’s moving. The camera following is on FixedUpdate to make sure it follows the rigidbody properly.
I’m wondering if anyone has any solutions for having a smooth following pixel perfect camera with a slight delay, or if there are any solutions to remove the warping behaviour you get from using a ‘Point’ filter?
I was even considering trying to limit the characters movement to be pixel perfect and if anyone has achieved this with a 2D rigidbody ?
Is the movement of your character also within the fixed update? If not then the camera will not follow with the same update speed, which I would think cause the ripple effect, or at least make it worse.
This is from a prototype and I haven’t tested this with a real game yet, but here’s a script I wrote that works. I attached it to everything that should be pixel-perfect at the time of rendering.
Physics can still use floats for positions and such, but when it comes to rendering, everything gets rounded. You have to use the 1 pixel = 1 unit setting though.
[edit] As for the camera, I used the one that came with 2D Toolkit. I set the native resolution to 320x240.
using UnityEngine;
using System.Collections;
public class RenderPixelPerfect : MonoBehaviour
{
private Vector3 realPosition;
void LateUpdate()
{
realPosition = transform.position;
transform.position = new Vector3((int) realPosition.x, (int) realPosition.y, 0);
}
void OnRenderObject()
{
transform.position = realPosition;
}
}
Thanks for the replies guys, I actually noticed that using rigidbody2D velocity to move the character is a bad idea .
So i used the move position function from the rigidbody instead and it seems like there is no weird warping effect on the tiles. I still can’t have a a slow moving camera because that would have to use float numbers which don’t play nice.
@Irlelaldl - Yes my character is in fixed update as well, just seems like velocity and pixel art don’t mix well.
@der_r - I actually tried using 1 pixel to units which solved some problems, but I didn’t like the fact that everything had to be huge. So reverted back to 100 pixels to units and just replaced my velocity function to use moveposition instead.
Ye the main problem is with pixel art and trying to have everything look pixel perfect, seems like because velocity would give you floating point numbers it makes your pixel art look weird at some points.
I didn’t even have to use the pixel perfect locking camera either to solve it