- Home /
BoxCast not working, CheckBox overshooting
I try to procedurally build rooms, what basically works well. But as soon as I try to implement more influence by the environment (obstacles like other walls or chimneys), there appear issues.
If I try to check the room-tiles position via BoxCast to recognize obstacles, colliders are not recognized. The flat and floating wall and the chimney have primitive, non-trigger box colliders:
The script I use to cast the BoxCast:
//Check if space is free
RaycastHit Hit;
if (Physics.BoxCast(NewFloorTile.transform.position, FloorTileDimension / 2, transform.up, out Hit, transform.rotation, 3f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore))
{
Debug.DrawRay(NewFloorTile.transform.position, transform.up * 3f, Color.red, 2f);
print(Hit.collider.gameObject);
Destroy(NewFloorTile);
}
else
{
Debug.DrawRay(NewFloorTile.transform.position, transform.up * 3f, Color.green, 2f);
//Name
NewFloorTile.name = "FloorTile";
//Reference
Tiles.Add(NewFloorTile);
}
If I try the CheckBox function, obstacles are correctly recognized, but also non-existing colliders appear (the cut-out corner at the bottom with the red DrawRays):
this code is used for the CheckBox:
if (Physics.CheckBox(NewFloorTile.transform.position + transform.up * 1.5f, new Vector3(FloorTileDimension.x / 2f, 3f, FloorTileDimension.z / 2f), transform.rotation, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore))
{
Debug.DrawRay(NewFloorTile.transform.position, transform.up * 3f, Color.red, 2f);
//print(Hit.collider.gameObject);
Destroy(NewFloorTile);
}
else
{
Debug.DrawRay(NewFloorTile.transform.position, transform.up * 3f, Color.green, 2f);
//Name
NewFloorTile.name = "FloorTile";
//Reference
Tiles.Add(NewFloorTile);
}
Any suggestions?
Your answer
Follow this Question
Related Questions
How to animate collider along with object for 2D game? 1 Answer
[SOLVED] Physics2D OverlapCircle 2 Answers
Physics artifacts on terrain seams 0 Answers