#camera lerping stuttering issue

1 messages · Page 1 of 1 (latest)

chrome furnace
#

i have this camera lerping code, which works as i want it to but my player stutters when moving around

local min = -10 
local max = 10
local Rigidness = 2.3 



local humanoid = script.Parent:WaitForChild("Humanoid")
local rootpart = script.Parent:WaitForChild("HumanoidRootPart")
local head = script.Parent:WaitForChild("Head")
local CamPart = Instance.new("Part")

CamPart.CanCollide = false
CamPart.Anchored = true
CamPart.Position = head.Position
CamPart.FrontSurface = Enum.SurfaceType.Motor
CamPart.Shape = Enum.PartType.Ball
CamPart.Size = Vector3.new(3,3,3)
local pos
game["Run Service"].Heartbeat:Connect(function(dt)
    if CamPart.Position.Magnitude > 10000 or CamPart.Position.Magnitude < -10000 then
        CamPart.CFrame = workspace.CurrentCamera.CFrame
    end
    pos = head.Position
    CamPart.Position = CamPart.Position:Lerp(pos,Rigidness*(dt*10))
    CamPart.CFrame = CamPart.CFrame:Lerp(CFrame.lookAt(CamPart.Position,head.Position),Rigidness*(dt*10))
    local calc = (rootpart.CFrame+Vector3.new(0,1.1,0)):Inverse() * (CamPart.Position)
    if calc.Magnitude > max/2 then
        workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(workspace.CurrentCamera.CFrame:Lerp(CFrame.lookAt(workspace.CurrentCamera.CFrame.Position,head.Position),Rigidness/(Rigidness*10)),Rigidness/(Rigidness*10))
    end
    humanoid.CameraOffset = Vector3.new(math.clamp(calc.X,min,max),math.clamp(calc.Y,min,max),math.clamp(calc.Z,min,max))

end)
rain otter
#

Heartbeat updates before the camera does

chrome furnace
rain otter
#
game["Run Service"]:BindToRenderStep("MyCameraLoop", Enum.RenderPriority.Camera.Value, function()
 Your code here... 
end)
quiet auroraBOT
#

studio** You are now Level 2! **studio

rain otter
#

If it still doesn't work, try adding/removing one from the second argument, I never know which one it is

#

like Enum.RenderPriority.Camera.Value+1

chrome furnace
rain otter
#

uh, try by putting 9999 instead of Enum.RenderPriority.Camera.Value

chrome furnace
#

not trying to be mean or anything but yeah

rain otter
#

Why is there a "calc.Magnitude" check?

chrome furnace
#

im not sure, i didnt really create the script i just modified it quite a lot

rain otter
#

Cause if it doesn't pass this condition, it doesn't update the camera at this frame

#

try removing the condition

chrome furnace
#

when i remove it, my player changes direction slightly when i zoom in.

rain otter
#

Yeah but is there the stuttering issue still?

chrome furnace
#

ehh

quiet auroraBOT
#

studio** You are now Level 6! **studio

chrome furnace
#

still looks like it yeah

rain otter
#

What does your current code look like?

chrome furnace
#
local min = -10 
local max = 10
local Rigidness = 2.3 
local humanoid = script.Parent:WaitForChild("Humanoid")
local rootpart = script.Parent:WaitForChild("HumanoidRootPart")
local head = script.Parent:WaitForChild("Head")
local CamPart = Instance.new("Part")

CamPart.CanCollide = false
CamPart.Anchored = true
CamPart.Position = head.Position
CamPart.FrontSurface = Enum.SurfaceType.Motor
CamPart.Shape = Enum.PartType.Ball
CamPart.Size = Vector3.new(3,3,3)
local pos
game["Run Service"]:BindToRenderStep("CameraLerp", Enum.RenderPriority.Camera.Value + 1, function(dt)
    if CamPart.Position.Magnitude > 10000 or CamPart.Position.Magnitude < -10000 then
        CamPart.CFrame = workspace.CurrentCamera.CFrame
    end
    pos = head.Position
    CamPart.Position = CamPart.Position:Lerp(pos,Rigidness*(dt*10))
    CamPart.CFrame = CamPart.CFrame:Lerp(CFrame.lookAt(CamPart.Position,head.Position),Rigidness*(dt*10))
    local calc = (rootpart.CFrame+Vector3.new(0,1.1,0)):Inverse() * (CamPart.Position)
    workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:Lerp(workspace.CurrentCamera.CFrame:Lerp(CFrame.lookAt(workspace.CurrentCamera.CFrame.Position,head.Position),Rigidness/(Rigidness*10)),Rigidness/(Rigidness*10))
    humanoid.CameraOffset = Vector3.new(math.clamp(calc.X,min,max),math.clamp(calc.Y,min,max),math.clamp(calc.Z,min,max))

end)
rain otter
#

This script doesn't manage the camera's movement, only the rotation

chrome furnace
#

should i be managing the movement also?

rain otter
#

You should have all of your code that changes the camera cframe running after all other stuff using the event I sent in the first place

chrome furnace
#

i just want the movement to look something like this, but only the stuttering is the issue i think

chrome furnace
#

thanks for the help

rain otter
#

and putting the camera's subject to this part

#

Should be simpler this way

chrome furnace
#

its still choppy looking for some reason

chrome furnace
#

and the camera position isnt where i want it

rain otter
rain otter
chrome furnace
#

hm okay

#

i have

local Rigidness = 18

local humanoid = script.Parent:WaitForChild("Humanoid")
local rootpart = script.Parent:WaitForChild("Head")

local CameraTarget = Instance.new("Part")
CameraTarget.CanCollide = false
CameraTarget.Anchored = true
CameraTarget.Size = Vector3.new(1, 1, 1)
CameraTarget.Position = rootpart.Position
CameraTarget.Parent = workspace
CameraTarget.Transparency = 1


workspace.CurrentCamera.CameraSubject = CameraTarget

game["Run Service"]:BindToRenderStep("CameraLerp", Enum.RenderPriority.Camera.Value - 1, function(dt)
    CameraTarget.Position = CameraTarget.Position:Lerp(rootpart.Position, Rigidness * dt)
end)
#

but im still confused how its choppy?!

#

i really dont understand why

#

and when i use + 1 it still does nothing different

rain otter
#

Whatever I changed your approach. My guess is that the order of updating is wrong somewhere down the line or I'm missing something obvious.

local Rigidness = 10

local humanoid = script.Parent:WaitForChild("Humanoid") :: Humanoid
local rootpart = script.Parent:WaitForChild("HumanoidRootPart") :: Part

local CameraTarget = Instance.new("Part")
CameraTarget.CanCollide = false
CameraTarget.Anchored = true
CameraTarget.Size = Vector3.new(1, 1, 1)
CameraTarget.Position = rootpart.Position
CameraTarget.Parent = workspace
CameraTarget.Transparency = 1

local a = Vector3.new()
function Lerp(a, b, t)
    return (1-t)*a + t*b
end
game["Run Service"].RenderStepped:Connect(function(dt)
    CameraTarget.Position = CameraTarget.Position:Lerp(rootpart.Position, math.clamp(Rigidness * dt, 0, 1))
    local Target = CameraTarget.Position - rootpart.Position
    
    a = Lerp(a, Target, math.clamp(dt / 0.05, 0, 1))
    humanoid.CameraOffset = rootpart.CFrame.Rotation:VectorToObjectSpace(a)
end)

CameraOffset sucks cause it's relative to humanoid's rotation. Best course of action would just to add the offset relative to world within a forked version of the default camera module.

lyric barn
chrome furnace
#

it looks way smoother than it was