I am making a game, and I am loading it in chunks. AKA: I load only 15 320240 pixel parts of the world at the time (2015 blocks). My only problems are collisions. They work properly only in the chunk (0, 0). Chunks in the same quadrant have a weird offset, like being 1 block above where it should be. In the other quadrants, it doesn’t work at all, because the collisions keep going to -1, which is out of bounds for my grid.
Here is my code, it is designed to take world coordinates and turn them into a chunk coordinate and then a chunk’s block coordinate:
public Block getBlock(float x, float y)
{
int chunkX = (int)( (x-(x%320))/320 );
int chunkY = (int)( (y-(y%240))/240 );
Chunk chunk = getChunk(chunkX, chunkY);
int blockX = (int)( x-(chunk.getX()*320) );
int blockY = (int)( y-(chunk.getY()*240) );
return chunk.getBlock(blockX, blockY);
}
I want to know why it isn’t working, the code seems perfectly sound, and the results a little random. It would be a great help if you knew why, and told me!