So I have a rooms game, and I make it so the entities lerp from start to finish. Usually it’s choppy, and the hitbox overshoots players. How can I fix this?
local RunService = game:GetService("RunService")
local part = script.Parent.MainPart
local alpha = 0
local speed = 50
local startCFrame = script.Parent.PrimaryPart.CFrame
RunService.Heartbeat:Connect(function(delta)
if script.Parent.Temp.Value == false then
local lastRoom = game.Workspace.Rooms[game.ReplicatedStorage.CurrentRoom.Value].Exit
local distance = (script.Parent.PrimaryPart.Position - lastRoom.Position).Magnitude
local relativeSpeed = distance / speed
local goalCFrame = startCFrame:Lerp(lastRoom.CFrame, alpha)
script.Parent:PivotTo(goalCFrame)
alpha += delta / relativeSpeed
if script.Parent.MainPart.Position.X < lastRoom.Position.X then
script.Parent:PivotTo(lastRoom.CFrame)
script.Parent:Destroy()
end
end
end)