Physics.OverlapSphere missing colliders.

We have a big monster in our game, that can hit multiple enemies at once with a big club. I’ve defined a couple of sphere helpers with a radius that I attach to the club, and on the impact time I loop through all these volumes with a Physics.OverlapSphere and collect the colliders.

However it seems that the physics.overlapsphere is returning very inconsistent results. Sometimes the monster has to hit a static object several times for the overlapsphere to register the collider. The problem seems to increase if the monster is attacking very fast.

This is afaik not a problem with fast moving object collision detection, since I can clearly see that the list of overlap spheres is in the correct position on the frame where the check is performed. I added a debug log message to list the colliders found on the impact frame, and below is a screengrab of that frame.

White wiresphere are the volumes checked for overlap with other colliders. Green capsule is the collider for the monster that the overlapshere does not detect.

Any ideas? Are there some differences between how the animation is updated and the physics that could cause this? It’s weird that it seems to work fine if the animation is slowed down, but that it does not register while stepping through frame by frame. Does the physis.overlapsphere wait until the next physics update to run?

Solved!

The problem was:

  • Sphere volumes used in Physics.OverlapSphere were linked to a bone.
  • Animations update after the Update() function, where the overlapsphere was called.
  • Result: OverlapSphere basically got checked against where the spheres were the previous frame, and with the high speed of the animation, the club was raised high in the air the frame before it hit the ground.

Now he hits everything, no matter the speed.

Just wanted to add to this one.

I was calculating OverlapSphere on an animation trigger. This also resulted in inconsistent colliders. It wasn’t until I put the OverlapSphere call in FixedUpdate that it was consistent.