public Voxel(Game1 game, Vector3 position, float size, Vector4 colour)
{
this.colour = colour;
this.game = game;
this.size = size;
colourTimer = new LerpTimer(1f, 0f, 2000);
// Reduce size by a small amount based on collision margins
// This prevent the voxel from overlapping neighbouring voxels when created
size -= game.Space.SimulationSettings.CollisionDetection.DefaultMargin;
// Entity can be obtained from EntityPool
entity = new Box(position, size, size, size, 1);
entity.IsAffectedByGravity = false;
game.Space.Add(entity);
}
The weird thing is that all the voxels don't stay put and instead expand away from each other. I thought they might be overlapping but I have tried reducing the size by the Default Margin and still nothing.
That is definitely caused by overlap. Try decreasing the size by 2 * DefaultMargin since the full expanded 'width' of a box is width + 2 * DefaultMargin (a margin on each side of the box). If that doesn't work, it might be related to some tuning designed for normal-sized objects (if objects get really really small, quite a bit less than 0.1). Or maybe it is related to the position calculation.
Another future-upgrade note: v0.15.0 considers box margins to be built into the box. Defining a width of 1 will give the box a total width of 1, with the margins going 'inwards.' Spheres and capsules also have 'inward' margins. Other shapes like MinkowskiSums and ConvexHulls still have outward margins.