I want to make a raycast projectile system, like fastcast (please don’t send me a link to fastcast as a solution). However, the projectiles speed changes based on framerate and I can’t really find a fix for it. Here is an example:
As you can see, the projectiles speed gets slower when the fps is lower, and faster when the fps is higher. If anyone knows how to fix this with some deltatime filtering or something like that, please reply. Thank you. Here is the code by the way if you want to examine it yourself:
--start is the origin vector3 and direction is a cframe lookvector
function createProjectile(start, direction, params, bullet)
local maxdist = 1000
local stepDistance = 1
local newStart = start
local newdir = direction * stepDistance
local defaultBulletClone = bullet:Clone() or defaultBullet:Clone()
defaultBulletClone.CFrame = CFrame.lookAt(newStart, newStart - newdir)
defaultBulletClone.Parent = workspace.Terrain
runService.Heartbeat:Connect(function(dt)
defaultBulletClone.CFrame = CFrame.lookAt(newStart, newStart - newdir)
local result = workspace:Raycast(newStart, newdir, params)
newdir -= Vector3.new(0, 0.0025, 0)
newStart = newStart + newdir
if result then
defaultBulletClone:Destroy()
return result
end
end)
end