I’m rendering objects to voxels using Physics.CheckSphere or OverlapSphere on colliders. It works fine as long as the object doesn’t have to rotate or move. Unfortunately I need to rotate the object. Is there a way to force the transform to update?
Here’s my code, Thanks!
private void RenderFreshTestCollider()
{
var colliderGO = new GameObject("test go");
BoxCollider boxCol = colliderGO.AddComponent<BoxCollider>();
colliderGO.transform.localScale = Vector3.one * 6f;
colliderGO.transform.Rotate(45f, 45f, 45f);
RenderCollider(boxCol, Color.magenta, true);
}
private void RenderCollider(Collider collider, Color color, bool overwrite)
{
var list = new List<Vector3>();
Vector3Int min = Vector3Int.RoundToInt(collider.bounds.min);
Vector3Int max = Vector3Int.RoundToInt(collider.bounds.max);
Debug.Log("collider.bounds.min " + min.ToString() + " collider.bounds.max " + max.ToString());
// collider bounds result (0, 0, 0) (0, 0, 0)
for (int x = min.x ; x <= max.x; x++)
{
for (int y = min.y; y <= max.y; y++)
{
for (int z = min.z; z <= max.z; z++)
{
if (Physics.CheckSphere(new Vector3(x, y, z), 0.5f))
{
list.Add(new Vector3(x, y, z));
}
}
}
}
Debug.Log("list.Count " + list.Count);
// result 1
voxelCore.AddEnvVoxels(list, Vector3.zero, color, overwrite);
}