My Raycasts don’t work on triggers, however I have Queries hit triggers
turned on in physics settings, I have also tried QueryTriggerInteraction.Collide
, but that does’t work.
However if I set my triggers to colliders it works, but I need them as a trigger, If I put them as a collider it breaks my game…(edited)
this is an example of my code:
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out hit, 2f, laneTrigger, QueryTriggerInteraction.Collide) && isMoving && laneNum == 2 || Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out hit, 2f, laneTrigger, QueryTriggerInteraction.Collide) && isMoving && laneNum == 0)
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.right) * hit.distance, Color.yellow);
Debug.Log("Right Hit" + hit.collider);
moveX = 0f;
isMoving = false;
}
else
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.right) * 2f, Color.white);
Debug.Log("Target not hit");
}