There are a few threads out there where people discuss raycasts that sometimes miss colliders. Apparently that cannot happen and people often claim that the order of events is causing the issue.
I am opening this new thread because I have a more isolated scenario with fewer sources for problems. This is what I have:
- A player that walks around.
- A rifle which is a child of the player.
- The rifle can spawn projectiles.
- A projectile has no parent, is independent and knows nothing about the player.
- These projectiles then move along their forward direction in each update (or fixed update; I tried both using the appropriate time step for each).
- Before moving, the projectile checks if there is anything that blocks the way, in which case it destroys itself.
- There are no rigidbodies in the scene.
- The only obstacle is a static box collider with a mesh (for visual purpose) and no other components.
When my player just stands in front of the wall and shoots at it, then all projectiles hit the wall. 100% of them. Every time. But when my player starts moving, the projectiles start to ignore the wall. This does not make any sense to me because the projectiles don’t even know about the player. They are not in the player’s hierarchy and know nothing about him. I can reach a miss rate of approximately 20% when my player moves parallell to the wall. Moving perpendicular to the wall results in a 100% hit rate. For some reason The angle seem to influence the results.
I would love to hear your thoughts and appreciate anyone who has encountered a similar issue.
I am drawing debug lines to represent the raycast. And I can confirm that none of the misses start / end within the collider. All of them start before the wall and end after the wall.