Lerp to change CFrame angles inconsistent with FPS

  1. What do you want to achieve?
    Consistent rotation and lerp speed across all fps speeds.

  2. What is the issue?
    Speed and rotation intensity go lower the higher the FPS.

Videos below

Expected behavior (60fps)

Behavior above 60fps (240fps)


  1. What solutions have you tried so far?
    Can’t find a solution on devforum, I’ve tried using this formula for the lerp alpha but it sorta makes it worse?
local lerpFactor = 1-math.exp(-20*dt)
dragging.CFrame = dragging.CFrame:Lerp(targetCF, lerpFactor)

Full script

runService.RenderStepped:Connect(function(dt)
	if dragging then
        -- mouse delta
		local delta = getMouseDelta()*3

		local height = math.clamp(delta.Magnitude/19,1.5,7)

		local targetCF = CFrame.new(mouse.Hit.Position - (dragging.CFrame.LookVector * height)) * CFrame.Angles(math.rad(delta.y)*dt*60,math.rad(delta.x)*dt*60,0)
		
		local lerpFactor = 1-math.exp(-20*dt)
        -- lerp
		dragging.CFrame = dragging.CFrame:Lerp(targetCF, lerpFactor)
	end
end)

-- removing rotation*dt*60 still has the issue
2 Likes

Interesting, I’ve done some testing seems like its not the lerp formula that is actually wrong since it works for the linear movement.

I believe it’s actually the mouse delta that is incorrect as it doesn’t regard state. I found this to be better:

local dragging = workspace.Part

dragging.CanQuery = false

local mouse = game.Players.LocalPlayer:GetMouse()

local UserInputService = game:GetService("UserInputService")

local oldMousePos = mouse.Hit.Position

local initialCFrame = dragging.CFrame

game["Run Service"].RenderStepped:Connect(function(dt)
	if dragging then
		-- mouse delta
		--local delta = (mouse.Hit.Position-oldMousePos)*100 --I'm guessing its because it's like setting an impulse once
		local delta = (mouse.Hit.Position-dragging.CFrame.Position)*10 --this seems to work better
		oldMousePos = mouse.Hit.Position
		
		--local height = math.clamp(delta.Magnitude/19,1.5,7)
		
		local rotationTerm = CFrame.fromOrientation(math.rad(delta.Z),0,-math.rad(delta.X))
		local targetCF = CFrame.new(mouse.Hit.Position)*rotationTerm

		--local lerpFactor = 1-math.exp(-10*dt)
		local lerpFactor = 1-math.pow(0.5,10*dt)

		-- lerp
		dragging.CFrame = dragging.CFrame:Lerp(targetCF, lerpFactor)
		
		--if delta.Magnitude > 0.001 then
		--	initialCFrame = dragging.CFrame
		--end
		
	end
end)

-- removing rotation*dt*60 still has the issue

Some testing on low and high fps, seems to be the same amount of rotation intensity.

1 Like

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