- Home /
Question by
iR3dyPlayZ · Jul 12, 2021 at 02:30 AM ·
physicsraycasthit
MY ray cast is stuck
my raycast isn't detecting the object and its also stuck at 0 but moves when its detecting, but i want the ray cast to move with the player and to always show.
void ObjectDetection()
{
RaycastHit sensor1;
RaycastHit sensor2;
RaycastHit sensor3;
RaycastHit sensor4;
Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out sensor1, 2);
Physics.Raycast(transform.position,transform.TransformDirection(Vector3.left), out sensor2, 2);
Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out sensor3, 2);
Physics.Raycast(transform.position, transform.TransformDirection(Vector3.back), out sensor4, 2);
Debug.DrawLine(transform.position, sensor1.point, Color.red);
Debug.DrawLine(transform.position, sensor2.point, Color.blue);
Debug.DrawLine(transform.position, sensor3.point, Color.green);
Debug.DrawLine(transform.position, sensor4.point, Color.black);
if (sensor1.collider == null | sensor2.collider == null | sensor3.collider == null | sensor4.collider == null)
{
Move();
//print("Haven't Hit Anyhing");
}
else
{
if (sensor1.collider != null | sensor2.collider != null | sensor3.collider != null | sensor4.collider != null)
{
print("Hit Something");
Debug.Log(sensor1.transform.name);
}
}
}
raycast.png
(278.6 kB)
Comment