Is there a way to calculate what the speed of a particle should be in order for it to travel a certain distance?
I know that we can easily get the speed by doing Distance / Lifetime, but when we account for Drag, which is the rate in seconds that the particle would take to lose half of it’s Speed, we appear in a totally different ballpark.
Using this equation one can get by how much the Velocity will be scaled given elapsedTime and drag
function dragVelocity(elapsedTime, drag)
return 2 ^ (elapsedTime * -drag)
end
Which means that we can project the trail a particle would take (if we’re just accounting velocity and drag) with the following code:
Projection Code (for visual)
local RunService = game:GetService("RunService")
local part = nil -- a part in the workspace
local drag = 10
local speed = 60
local duration = 1
local direction = Vector3.new(0, 0, -1)
local origin = Vector3.new(0, 1, 0)
local previous = origin
for i = 1, 3 do --> this delays the sever a bit to execute the script
wait()
end
local start = tick()
local dt = 1/60
while true do
local now = tick()
local elapsedTime = math.min(duration, now - start)
local decayFactor = dragVelocity(elapsedTime, drag)
local velocity = direction * speed * decayFactor
part.Position = previous + direction * velocity * dt
previous = part.Position
if elapsedTime == duration then
break
end
RunService.Stepped:Wait()
dt = tick() - now
end
print("Distance travelled:", (origin - part.Position).Magnitude)
I might’ve missed a physics equation or something, but is there anyway I can use Drag = 10 as a constant, and figure out how much I would need to change the speed by to reach a certain distance of lets say, 30 studs?
I looked over this post but their equation looked more-so for linear velocity, and wasn’t that accurate.
This might be wrong but nevertheless is worth a try, you can use the motion in one dimension position equation (movement law, not sure what it’s called in English but that is the exact translation)
It says as follow
x is the position, v velocity, a acceleration and t time
x0 is initial position and so on with the rest
x(t) = x0 + v0 t + 1/2 * a * t
that gives you the position, with some algebra you can find any variable there
So now let’s fill out the equation
x(t) is the final position, so it’s the distance
the distance will be 30 studs for this example, as you mentioned it in your post
x0 will be 0, and a will be the drag. Since drag is opposite the movement, it will be a = - drag
t will be 1 as you said duration = 1
With this said, we get:
30 = 0 + v0 * 1 + 1/2 * (-10) * 1^2
With some algebra we get
30 = v0 + (-5) <=> v0 = 35
So, if all is correct and this is a valid option, you should set the speed to 35.
I hope this is not too confusing, and I hope this works as well.
Nevertheless, I had a great time writing this reply. Happy coding
Hey, thanks for the reply and projecting me toward something helpful!
The teardown was excellent & understood everything very well, this is the formula to find virtually any value in the equation but because the velocity of Particle Emitters on roblox get scaled by a decay factor when they have Drag, I’m guessing that the acceleration should be phrased differently or should be something that’s not a constant… not sure if that makes sense, or how I would apply that to the equation
the problem intesifies
I came across a helpful post which includes the solution to a problem similar to mine by formulating the equation to find distance where velocity is decelerating exponentially, but needed assistance with some of the conversion since this is Calculus level work.
In the article, the user states that the velocity over time is calculated by v0 * a where v0 is the initial velocity, and a is the deceleration rate based on time, in my case is calculated by the equation dragVelocity
The user later states that we need to find the indefinite integrals (Anti-derivates) of the velocity over time (dragVelocity), which we can determine as -v0/k * dragVelocity(t, drag) / math.exp(2)
Now, where I seem to get stuck in understanding is how they convert their indefinite integral equation from -v0/k * math.exp(-k*t) to v0/k * (1-math.exp(-k*t)
What method is the user doing to convert his equation & how would I convert my indefinite integrals using the same method?