[SOLVED] Projectile raycast misses up to 20% but only when the object that spawns the projectile is moving

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:

  1. A player that walks around.
  2. A rifle which is a child of the player.
  3. The rifle can spawn projectiles.
  4. A projectile has no parent, is independent and knows nothing about the player.
  5. These projectiles then move along their forward direction in each update (or fixed update; I tried both using the appropriate time step for each).
  6. Before moving, the projectile checks if there is anything that blocks the way, in which case it destroys itself.
  7. There are no rigidbodies in the scene.
  8. 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. :slight_smile:

Additional thoughts:
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.

I solved the issue.

For some reason the hit result for the static wall collider sometimes claimed to be a trigger (by the isTrigger property). No idea why. This seems to be a bug to me. My projectiles ignored collisions with triggers. I solved the issue by specifying QueryTriggerInteraction.Ignore explicitly during my raycast and not manually ignoring triggers after a raycast hit occured.