I wrote some script to check if a vertex is inside cube, but Raycast without RaycastHit is not working.
Here is the code.
void OnDrawGizmos()
{
Gizmos.color = Color.red;
foreach (Vector3 point in hitPoints)
{
Gizmos.DrawSphere(point, 0.01f);
}
}
Raycast(Vector3 origin, Vector3 direction)
void Update()
{
hitPoints.Clear();
Vector3 origin = transform.position;
foreach (Vector3 vert in vertices)
{
int count = 0;
Vector3 worldPoint = transform.TransformPoint(vert);
if (Physics.Raycast(worldPoint, Vector3.up))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.down))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.left))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.right))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.forward))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.back))
{
count++;
}
if (count == 6)
{
hitPoints.Add(worldPoint);
}
}
}
No Spheres are showing means hit count wasnāt 6.
Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo)
void Update()
{
hitPoints.Clear();
Vector3 origin = transform.position;
foreach (Vector3 vert in vertices)
{
int count = 0;
Vector3 worldPoint = transform.TransformPoint(vert);
RaycastHit hit;
if (Physics.Raycast(worldPoint, Vector3.up, out hit))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.down, out hit))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.left, out hit))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.right, out hit))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.forward, out hit))
{
count++;
}
if (Physics.Raycast(worldPoint, Vector3.back, out hit))
{
count++;
}
if (count == 6)
{
hitPoints.Add(worldPoint);
}
}
}
But with this code spheres are showing as I wanted to do.
What is wrong with Raycast without RaycastHit parameter?
It happened 2 years ago as I remember and itās still not fixed.

