- Home /
Camera to TileMap Clamp
I'm really quite stuck on this, so anything is welcome!
My issue's the following: I've got a TileMap generator, and I want my camera to clamp to this TileMap (not with box collide stuff, pure coding!) Now I've got the feeling I almost tried everything, but I'm obviously missing something. When I try to clamp my Camera the following way (this is along the X-Axis):
MoveTo.x = Mathf.Clamp(Target.transform.position.x,
(CameraWidth / 2),
(Global.MapWidth * Global.TileSize) - camera.orthographicSize * camera.aspect);
It gives a value, which is of course well calculated, but this does not fit the TileMap. Everything has been debugged and all the values are right:
Global.TileSize = 1.6
camera.orthographicSize = 4
CameraWidth = 2 * camera.orthographicSize * camera.aspect
Anything I seem to do returns this: a little bit too much spacing, a little bit too loosened. Now I'm really quite eager to know how this has to be done! (and I mean ANY screen resolution, no hard coding). Anyone knows what I'm doing wrong and even better how it should be done?
Thanks in advance!
I've already tried converting a camera for XNA to Unity, but to no avail. Anyone thoughts on this?
Answer by Malfegor · Sep 09, 2014 at 10:40 AM
Fixed it, I thought the origin of my tiles was in the left upper corner, but it was actually in the middle, so instead of
Global.Tilesize
I had to do
(Global.TileSize / 2)
How stupid of me!