Hey, I am developing a weapon system for my game. I’m currently trying to simulate a sonic boom
or a cracking noise produced by a bullet. I know the players’ position, the bullet velocity, and the bullet position.
This image illustrates the effect I want to achieve, but I have no idea how to replicate this effect in Roblox.
Visually, it’s a cylinder that expands and fades into transparency. You could use beams, particle emitters, really there’s quite a few options depending on how you’re handling bullets.
Hey, thank you for responding
I’m handling the bullet on the client so that wouldn’t be a problem.
I don’t think actually creating sphere parts would be the best solution, but is there any way to do this with just code and math? I’m trying to figure out when the observer should hear the supersonic boom
You can use the speed of sound and the position of the plane to calculate when the noise will reach a position (in this case the position of a player)
EDIT:
Here’s how:
The speed of sound is 340 m/s.
You can calculate the time by using this equation:
Also, we calculate the distance by using the difference between each position.
Quick script to calculate it and print it:
local speedOfSound = 340 -- Speed of sound
local position = Vector3.new(0,5,7) -- Position of plane
local playerPosition = Vector3.new(7,5,7) -- Position of player
while wait() do
position += Vector3.new(3,0,0) -- Movement of plane
local Time = Vector3.new(math.abs((position.X-playerPosition.X))/speedOfSound,math.abs((position.Y-playerPosition.Y))/speedOfSound,math.abs((position.Z-playerPosition.Z))/speedOfSound) -- Calculating time in 3 dimensions
print(Time) -- printing
end
Kind of. You would use the distance magnitude and delay the sound.
Let me explain with a script:
local speedOfSound = 340 -- Speed of sound
local position = Vector3.new(0,5,7) -- Position of plane
local playerPosition = Vector3.new(7,5,7) -- Position of player
local RunService = game:GetService("RunService")
local function delay(n) -- more precise delay
n = n or 0.05
local startTime = os.clock()
while os.clock() - startTime < n do
RunService.Stepped:Wait()
end
end
while wait() do
position += Vector3.new(3,0,0) -- Movement of plane
local Time = math.abs(position.Magnitude-playerPosition.Magnitude)/speedOfSound -- Calculation of how long it should take until you hear the noise
delay(Time) -- Delay
-- Turn on sound
end
I tried following this video and managed to recreate the effect I want in GeoGebra. However, I don’t know how I would do the same in Roblox’s 3D environment.
It calculates the distance between the Player (workspace.Player.Position) and the Plane (workspace.Plane.Position) then calculates the time it should take (Distance/Velocity), waits the amount of time it should take then plays the Sonic Boom sound (workspace.SonicBoom).
Hope this works.
local distance = math.abs((workspace.Player.Position-workspace.Plane.Position).Magnitude) -- Distance between player and plane.
local velocity = 510 -- Mach 1.5 (1.5*340 = 510)
local Time = distance/velocity -- Time it should take until you hear the sound.
wait(Time) -- Waits the amount of time it should take.
workspace.SonicBoom:Play() -- Plays the sound.