Hi all,
Here’s my problem: When I insert the pentamino X into the grid, it enters step by step.
The same thing happens in the opposite direction when I take the pentaminoX out of the grid.
What I’d like is for the pentamino X to enter or exit all at once
(not in bits of yellow numbers).
Strangely enough, with the following code, the left side works perfectly (see animation below), but the other 3 sides go in or out little by little.
Here is my code:
private void Update()
{
var changedFigures = Figures.Where(i => i.hasChanged);
if (changedFigures.Count() != 0)
{
ResetGrid();
foreach (var figure in changedFigures)
{
foreach (Transform box in figure)
{
Vector3 firstGridSquarePosition;
firstGridSquarePosition = new Vector3(grilleRouge.objArray[0].transform.position.x, grilleRouge.objArray[0].transform.position.y, grilleRouge.objArray[0].transform.position.z);
int x = Mathf.FloorToInt((box.position.x - (firstGridSquarePosition.x - 0.8f) ) / 1.6f ) ;
int z = Mathf.FloorToInt((box.position.z - (firstGridSquarePosition.z - 0.8f) ) / 1.6f ) ;
if (PositionIsValid(x, z))
{
grid[z, x] = 1;
}
}
}
}
}
private bool PositionIsValid(float x, float z)
{
return x >= 0 || x < GridSizeX && z >= 0 || z < GridSizeZ;
}
void ResetGrid()
{
for (int z = 0; z < GridSizeZ; z++)
{
for (int x = 0; x < GridSizeX; x++)
{
grid[z, x] = 0;
}
}
}
and a video that tells us more:
If you have some code here is where you can put it:
private bool PositionIsValid(float x, float z)
{
return x >= 0 || x < GridSizeX && z >= 0 || z < GridSizeZ;
}
you are welcome,
A+