Something is wrong with calculation of TilePos to real x/y #603
Unanswered
miketwenty1
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
While having a sprite walk to a TilePos, I think there may be a bug/logic issue in my code with how the X or Y axis is being produced.
Below is a function of a Sprite "Hal" walking to a TilePos. The Tilemap and the TileBundle have an anchor of
TilemapAnchor::BottomLeft
used for their Transform. I need to invert the Y value, which seems reasonable (y: -tile_center.y,
), but in order for me to get him to walk to the correct location I need to also add half the amount of the total height of the TilemapBundle. (i.e.y: -tile_center.y + (BUILDING_CHUNK_SIZE.x as f32 * TILE_SIZE.x / 2.),
).Granted
pub const BUILDING_CHUNK_SIZE: UVec2 = UVec2 { x: 16, y: 16 };
So in other words he's off by 8 tiles in the downward direction and I need to compensate for this as show above.
If I instead use
TilemapAnchor::Center
My Sprite is off by the same 8 tiles or half the chunk size in the X axis direction (left of the mark).I feel like I'm doing my due diligence when setting the Transform of these tiles when I spawn them. i.e
Any ideas if this is a bug with my code or a bug with how the original Tile Transforms?
Beta Was this translation helpful? Give feedback.
All reactions