My raycast is going right through my meshes quit often. In the picture below the origin is NOT moving, is NOT inside the collider, and is layermasked to ignore the player’s collider, which is start inside of anyway. Repeating the same raycast over and over it’s a total hit and miss. I’ve added kinematic rigidbody, tried it without, etc. It hits then it doesn’t hit, then it doesn’t hit, then it hits again.
I’m totally confused. I’ll start testing with a simple box collider but… there are literally no factors changing between the times it hits and the times it misses…?
if (Input.GetKeyDown(KeyCode.Q)) {
Ray harvestRay = new Ray(camTarget.position, cam.transform.forward);
hit = new RaycastHit();
if (Physics.Raycast(harvestRay, out hit, 3f, nonplayerMask)) {
Debug.DrawRay(harvestRay.origin, hit.point - harvestRay.origin, Color.green, 5f);
}
else {
Debug.DrawRay(harvestRay.origin, cam.transform.forward * 3f, Color.red, 5f);
}
}