I am trying to make a character tilt while running based on the direction the camera moves.
After testing with different frame rates it appears the character tilts more the lower the users fps is.
I have tried many things including using TweenService instead of lerp to see if it resolves the issue because I might have missed something regarding delta time.
I have came to the conclusion it is something with the mouse delta sensitivity or something along the lines but I have no idea how to resolve the issue and I’d appreciate some insight.
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local rootPart = script.Parent:WaitForChild("HumanoidRootPart")
local rootJoint = rootPart:WaitForChild("RootJoint")
local basec0 = rootJoint.C0
RunService.RenderStepped:Connect(function(dt)
local mouseDelta = UserInputService:GetMouseDelta()
local deltaX = mouseDelta.X
if rootPart.Velocity.Magnitude >= 16 then
rootJoint.C0 = rootJoint.C0:lerp(basec0 * CFrame.Angles(0,-deltaX/20,-deltaX/20), dt * 5)
elseif rootPart.Velocity.Magnitude < 16 then
rootJoint.C0 = rootJoint.C0:lerp(basec0, dt * 10)
end
end)