Im trying to make a bullet whiz effect (when bullets flies near players head), im using fast cast for the bullet system
i tried putting the sound into the bullet and play it but didnt work really well
I appreciate every reply.
Im trying to make a bullet whiz effect (when bullets flies near players head), im using fast cast for the bullet system
i tried putting the sound into the bullet and play it but didnt work really well
I appreciate every reply.
Are you using a ‘whizz’ sound effect? As I imagine it was recorded from the point of view of stationary listener. From the point of view of the moving bullet it emits a constant sound, it is the fastpaced Doppler effect which gives it the characteristic whizz sound.
So you could detect when the bullet part comes into range of a player then play the whizz effect on the client. Or. You could add a constant ‘hum’ to the bullet, and hope the sound rendering keeps up. Although with lag etc this may not be ideal.
I have been thinking the same thing. But fear not I might have an answer
You see when simulating bullet whiz you would want to calculate the closest distance between the bullet direction and the player’s head
And upon further research I came across the formula for the dot product. People mainly use the Dot Product for checking if an npc has a thing in it’s “field of view.” However that uses the behaviors of two normalized vectors, if the “directional” vector is normalized and the positional vector is not normalized then they have a little quirky quirk, take a look
gasp its exactly what we need to calculate the distance!
Anyway I spared you the mathy stuff to calculate it, and wrote a simple little api! And I even wrote in using OOP to allow for easy plugins for modules like FastCast
(usage and docs are inside of the module)
EDIT: due to the fact that bullet whiz should ONLY be calculated on the client, the module has api core to the client only! Also if you want camera shake you can calculate that from the distance value returned with Check, I only hardcoded in the sfx.
Edit2: the code im using to display the bullets whizzing by are as follows, it replaces the Object every .25 seconds, normally you would want to make it only create one bullet object for every bullet, so the whizz sfx will only play one time when the bullet goes past
Just put a Part temporarily on the client to the left, or front, or wherever the bullet is passing by) of the player’s head with the whiz sound loaded into it and play the sound (a doppler effect “bullet passing by sound”, not a constant buzz) there.
You won’t get the actual stereo movement of the sound (say if it was passing in front of their face from left to right) but I can’t imagine it would make that much of a difference while playing.
well how exactly would you put a part temporarily in the direction the bullet is passing by?
Most bullets are moving so fast between frames that you dont know the real closeness to the bullet, or the direction
Plus to the stereo bullet whizzing past a player, the bullet is usually moving way too fast to hear the bullet come and leave, plus the bullet whizzing is caused by the speed of sound being broken which results in a cracking noise as shown in this video
edit: the entire point of my module is to use the math I detailed above to find where to position the bullet whizzing sfx in relation to the camera and place the part, which does provide stereo sound
I hadn’t even thought about directional sound.
One idea I had was to use raycasting and a ‘soundhitbox’ around the player. Depending on what trajectory the bullet is taking you could get the point at which the raycast enters the box and play a DopplerApproach sound, and a DopplerExit sound at the point where it leaves.
Audibly, as the approach sound will be higher pitch louder and shorter, you should be able to get away with not calculating the exact magnitude between the points.
And if the raycast hits the player then just play the approach and a thump.
You theoretically could do that I guess. But for the doppler effect to play effectively it would require a massive hitbox, almost mapwide. Then you would need edge cases for if the bullet originates inside of the hitbox or not. Plus you would still need to do math to stop every bullet from playing a sound
Doppler effects come into play mostly when the object is going ~60-120 mph. When the object is over 600 miles per hour though, you could totally get away with a little “thwip” for subsonic projectiles and a “crack” for supersonic projectiles once the bullet passes the player
The purpose of the module is to not only calculate the magnitude of how far the sound is from the player, but calculate the exact position the part should be relative to the camera. Its only overhead is the dotproduct formula ((p1.x * p2.x) + (p1.y * p2.y) + (p1.z * p2.z)) and a few add and subtract things. Its a lot more performant than any way of approximating the magnitude between the points
If we base our sounds on impact position then if the bullet goes past our head but continues into void then the player wouldn’t get any whiz sfx
If we base our sounds on bullet position then if bullets are going extremely quickly then you can get inaccuracies between two frames which is what I was trying to bring out here (especially if its a hitscan gun, the only two points of reference are the fire point and the end point)
thank you really much for the time and explanation, it works really good
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.