How can I make players hear bullets before a gunshot?

Since bullets go faster than sound, I want my players to hear the bullet whizzing by BEFORE they hear the gunshot.

The only way I can think of doing this is checking the distacne to each player from the bullet and cloning and playing the sound at a certain point, but i feel like this will be hacky and awkward, is there any modules for it that do it already?
Thanks.

3 Likes

Hey, I don’t think that’s how it works in real life when we’re talking about guns…

I mean, you could add a wait before playing the sound, but that’s seriously not how guns work in real life.

1 Like

It is.

If you’re shot at, from, lets say a sniper from a long distance:

First, you will see the muzzle flash, then, you will be hit by the bullet almost instantly after the muzzle flash, then you’ll hear the sound. It depends entirely on distance.

2 Likes

Why not just have the sound already in the bullet then check the distance locally and play it locally?

Well its simple. just place first on script sound. like this.

sound:Play()
wait(0.0001) -- mini delay
--gunshot here

I don’t think this is really a valid solution…

you’re totally ignoring the distance factor meaning if you are standing right next to the gun the bullet will still be just as delayed as if you were standing 1,000,000 studs away

1 Like

then check distance between player and gun by magnitude.

You can delay the gunshot sound and play a whizzing sound locally as the bullet passes by the character.

You can calculate how long to delay the gunshot sound based on the distance between the character and the gun.The time you need to delay the gunshot by is equal to the amount of time it would take the sound to reach the character.

v = d/t
t = d/v

Where t is the time the sound would take to travel the distance d at velocity v.

Now, using this information:

-According to the Roblox Blog, 20 studs = 1 meter

-The speed of sound in air is ~343 meters per second

Let’s call the distance between the character and the barrel of the gun in studs d, which can be calculated as:

d = (Character.PrimaryPart.Position - Barrel.Position).Magnitude

That means that the time you need to delay the gunshot sound by is:

T = d / 20 / 343

At this point, you should realize that this time is insignificant, because in the scope of a Roblox game, the distance between the gun and the character is unlikely to exceed 100 to 1000 studs, and at a distance of 100 studs, the delay would only be 0.0146 seconds, which is less time than it takes to render a single frame at 60 fps, and at a distance of 1000 studs, it’s only a 0.146 second delay, which is still incredibly small given all of the other factors you have to account for, such as any empty time at the beginning of the gunshot sound or whizzing sound, latency, etc.

In other words, this is probably not worth your time to create, unless you’re planning on making some sort of game with long range sniping at distances that would likely exceed the client’s render distance, or unless you’re not planning on following real-world physics.

6 Likes

This seems great, i’d like to add that 20 studs is NOT a meter, this would make the players tiny, we’re talking player size compared to the world around them, if you check the gravity settings it comes out to roughly 3.57 Studs in a meter, the 20 studs per meter is a myth and refers to modelling scales.

That’s incorrect. According to the blog article I linked in my reply, Roblox’s gravity is consistent with the 20 studs per meter conversion.

In ROBLOX, one real-world meter is 20 studs. We can use that conversion to determine ROBLOX’s acceleration due to gravity. In the real world, acceleration due to gravity is 9.81 meters / second^2. When we multiply that number by 20 studs, we arrive at the acceleration due to gravity in ROBLOX: 196.2 studs / second^2 .

Yes, but not in roblox character to roblox world scale.

" I think there’s finally a canon answer. With the release of World Panel Settings, 1 stud is exactly 0.28 meters (50/14 = 0.28). That’s ~0.92 feet in imperial units. I’m guessing this scale was made with RThro proportions in mind. A door would be roughly ~7.2 studs high and 36 studs wide (assuming that the average door is 6’8" tall and 3’ wide.)"

1 Like

For example, if we say there is 20 studs in a meter in this term, if we wanted to make a football field 100m long, it would be too long compared to the player, considering the player is only what, 5-6 studs high and every “meter” would be 20 studs long.

1 Like