Issue Getting Block Correctly from Coords

Hey guys. Right now I’m trying my hand at a small voxel engine, but unfortunately I’ve run into an issue. For some reason I can’t seem to be able to convert world coords into chunk coords. My current code for getting the chunk from the world coords is :

public Chunk GetChunkByWorldPos(Vector3 pos)
    {
        Vector3 chunkPos = new Vector3((int)(pos.x / World.staticChunkSize), (int)(pos.y / World.staticChunkSize), (int)(pos.z / World.staticChunkSize));
        return GetChunkByPos(chunkPos);
    }

To me it seems good but when I test it I get this.

On the 3rd line down is where I show the chunks. The left is a raycast showing what chunk it hits and on the right is the chunk the code gets back. Any ideas on where I’m going wrong? And if you need to see anymore code just let me know.

Casting float to int will round its value towards 0, i.e. it will behave differenly for negative and positive values. Try to use Mathf.Floor or Mathf.Ceiling to get consistent results.

public Chunk GetChunkByWorldPos(Vector3 pos)
{
    Vector3 chunkPos = new Vector3(Mathf.Floor(pos.x / World.staticChunkSize), Mathf.Floor(pos.y / World.staticChunkSize), Mathf.Floor(pos.z / World.staticChunkSize));
    return GetChunkByPos(chunkPos);
}

Thanks mate, that solved it