Hello, I’m wondering how do you predict a projectile’s position? Currently I’m using the formula:
d = st
Example:
local cooldown = 0.5
local speed = 10
local direction = (mousePos - origin).Unit
local lastPos = origin
while true do
lastPos = lastPos + direction * (speed * cooldown)
task.wait(cooldown)
end
Yet, for some reason this is behind the actual projectile. Also I’m using a linear velocity inside the projectile. Any ideas?
But it could also be a task.wait() thibg since it waits the maximum amount of time so it may wait 0.51 seconds instead with an extra 0.1 seconds which build up inacxuracies.
Try using the delta time returned by task.wait instead.
That’s a good point after checking the time you can notice a small delay. However, I tried using delta time instead like you said, but I still noticed a small delay am I doing it right?
Script:
local cooldown = 0.5
local speed = 10
local direction = (mousePos - origin).Unit
local lastPos = origin
local lastTime = time()
while true do
if time() - lasTime >= cooldown then
lastPos = lastPos + direction * (speed * (cooldown + task.wait()) )
lastTime = time() + task.wait()
end
task.wait()
end
It turns out I wasn’t suppoed to add task.wait((), so this is actually more accurate and this ended up being the solutions! However, there is still a small acceptable delay though. I think I can work with that.