Home > Net >  Unity tilemap rendering offsets as soon as camera moves
Unity tilemap rendering offsets as soon as camera moves

Time:10-27

I'm following a unity tutorial and made a very basic top-down 2D scene using tilemaps. Starting up the game the rendering seems fine, but as soon the camera moves along the Y axis, the tiles seems to "move apart". Also, the sprites I use seems to get an offset for the tile-map, as if they were cut incorrectly. (1 pixel dilation on the y axis.)

Before moving: Before moving

After moving: After moving

Any ideas why this happens and how to deal with it?

My issue seems to be something like this one, but there were no answers here. Another thread found a solution to a similar issue, however I couldn't make this work, as Unity does not allow me to directly change the Pixel Snap property of the shader, but says "MaterialPropertyBlock is used to modify these values".

CodePudding user response:

I have some ideas here:

I found this video which uses a SpriteAtlas to alleviate a similar problem. The person mentions also setting the Filter Mode to Point for the Sprite Atlas, along with Compression set to High Quality.

Also double check that your sprites are setup the same way... Point (no filter) and High Quality Compression. I think I remember there being an option for NO compression... that might be worth a shot as well, since I think that most 2d images are already compressed.

I also remember there being a "Pixel Perfect Camera", as documented here:

It specifically mentions being a good solution "which ensures your pixel art remains crisp and clear at different resolutions, and stable in motion.". The basic idea is that you use the Pixel Perfect Camera Component, and use settings similar to what was mentioned above.

For your sprites:

  • Filter Mode: Point (no filter)
  • Compression: None
  • Use the same Pixels Per Unit for each
  • With the Sprite Editor, set all the sprites Pivot Unit Mode to "Pixels".
  • Set your snap settings to 1 / Asset Pixels Per Unit (and apply to existing Game Object)

There are also specific settings for the Pixel Perfect Camera component.

CodePudding user response:

This is possibly just a floating point precision error caused by your tile calculation somewhere.

There are a number of complex fixes that are the "right" way to do it, but a quick an easy fix is to move the tiles closer together by a very small amount (0.0001f). If this doesn't fix it, its probably not a precision error.

  • Related