How to make a bullet whistle next to a player in Unity?
Good evening everyone.
I have been trying to solve this question for a long time, but, alas, I have not yet found an answer. I ask for help here.
Objective: to achieve the whistling effect of a bullet flying near the player (past him) at a certain distance, in a game with a first-person view. The bullet does not have a collider (the object sends out rays that register a collision with something). In this case, the shooting itself does not occur with a beam, the bullet with which it was fired moves along the calculated trajectory - i.e. it is exactly the object.
Examples of the bullet whistling effect that I'm talking about can be heard in COD Warzone, Arma 3, Escape from Tarkov. It's not about the sound effect, which is part of the impact - when the sound of hitting the surface is simply replaced or added with a whistle sound. As I understand it, this is exactly an object flying by, which can "pierce" any surface 200 meters away from the player, and he will not hear the sound of the contact between the bullet and the surface.
Trying to simply attach an Audio Source to the bullet with a bullet whistle sound gives strange results: the sound is highly distorted and doesn't always work. It looks like Unity has problems with voicing objects so fast this way.
I heard about two more ways: 1.the distance from the fired bullet to the player is calculated and when the distance is reduced to a certain value, the sound source hung on the player, and not on the bullet, is triggered and the player hears the whistle of the bullet. 2. a SphereCast is hung on the player, which takes into account the moment when the bullet collided with him / entered him (for example, using the tag system) - again at this moment the sound source on the player is triggered.
I do not quite understand how this can be implemented, while all attempts are unsuccessful. Or maybe there is some other simpler / reliable way to solve the problem?
Here is a video explaining what I'm talking about: https://www.youtube.com/watch?v=VTuuOiWgVZ0&feature=youtu.be