Interesting. Where’d you put the code that handled the .1 => 1 pixel code? It works nicely. I like ray-casting. It gives me a nice sense of satisfaction when I get it working.
I ended up adding a child GameObject that held the sprite and animator (in my case). The parent object has the collider and rigidbody. I let the physics engine move the overall object. The child object that renders the sprite would then round the parent’s position and set its own position accordingly. The collider is a factional pixel off, but that was fine for my needs.
void Update()
{
if (SnapToPixel)
{
Vector3 roundedPos = transform.parent.position;
roundedPos.x = Mathf.Floor(roundedPos.x);
roundedPos.y = Mathf.Floor(roundedPos.y);
SpriteRenderer.transform.position = roundedPos;
}
}