How can i control the speed of non physics projectiles

So i have an anochored part that i want to move to a direction.

like:

while task.wait() do
	script.Parent.CFrame = CFrame.new(script.Parent.Position + script.Parent.CFrame.LookVector)
end

but people with lower fps will experience slower bullet. so how would i control the speed of the bullet to be as the desired speed as i want and how would i make it run the same for everyone?

1 Like

You need to use the DeltaTime. Right now i’m on phone it’s difficult to modify the script but someone will do it, or just look on the devforum how to add the DeltaTime (dt)

1 Like

Yeah i read it, is something like that work?

while true do
	local _,currentTime = wait()
	local dt = currentTime-lastTick
	print(dt)
	
	lastTick = currentTime
	script.Parent.CFrame = CFrame.new(script.Parent.Position + script.Parent.CFrame.LookVector*dt)
end

I’m not sure it will work but i may work. Otherwise thé way is to do like

local RunsService = game:GetService(“RunService”)

And inside the while task.wait()
local dt = RunService.Heartbeat:Wait()

And you need to remove the task.wait() for a while true do

game:GetService("RunService").Heartbeat:Connect(function(dt)
	script.Parent.CFrame = CFrame.new(script.Parent.Position + script.Parent.CFrame.LookVector*dt)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.