UCC Feature Request: Near miss audio

devomage

Member
If a projectile/hit-scan is within tolerance of a player and does not hit > play an audio. Also, if possible, supply enter/exit points of projectile moving through the tolerance area.
 
For hitscan you could do this by creating a layer like NearMissDetection that only interacts with itself. Then add an empty with large collider to the player that is on that layer. When the hitscan fires, it does not fire on that layer, instead a second raycast fires only on that layer. If the first raycast didnt hit the player, check if the second hit the near miss collider. If it did, you then have to check if the first raycast hit something farther from the hitscan origin than the second one. if it did, play the near miss audio. The last step is because the near miss raycast will not detect level colliders, so you determine if it should have reached the player or stopped short based on where the first raycast ended.

For a projectile, I'm not sure about the performance of this but you could do the same thing using a sphere cast on the NearMissDetect layer. You would need to this because if you just used a trigger or collider, if the projectile moves too fast it might completely miss detecting the player in one physics tick (one tick it's in front, next it's behind, no collision detected). So instead you are sending the sphere cast forward to detect what is in front of the projectile position between that tick and the next tick. Basically the distance you send it is the distance the projectile will cover in the next physics tick.
 
Last edited:
Top