i have this wallrun script that tilts the camera based on the side the wallrun is happening but for some reason the glitches when the tilting is over
code:
local tiltAngle = 15
local currentTilt = 0
local targetTilt = 0
runService.RenderStepped:Connect(function()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = filter
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.IgnoreWater = true
local origin = root.Position
local Rdirection = root.CFrame.RightVector * 3
local Ldirection = root.CFrame.RightVector * -3
local Rdistanceray = workspace:Raycast(origin,Rdirection, raycastParams)
local Ldistanceray = workspace:Raycast(origin,Ldirection, raycastParams)
targetTilt = 0
if Ldistanceray and not Rdistanceray and landed == false and climbing == false and holdingSpace == true and torso.Velocity.Y > -40 and torso.Velocity.Y < -1 then
targetTilt = -tiltAngle
--wallrun Left
elseif not Ldistanceray and Rdistanceray and landed == false and climbing == false and holdingSpace == true and torso.Velocity.Y > -40 and torso.Velocity.Y < -1 then
targetTilt = tiltAngle
--wallrun Right
elseif Ldistanceray and Rdistanceray and landed == false and climbing == false and holdingSpace == true and torso.Velocity.Y > -40 and torso.Velocity.Y < -1 then
--wallrun on both sides
elseif (landed == true or holdingSpace == false) or (not Ldistanceray and not Rdistanceray) or (torso.Velocity.Y < -35 and torso.Velocity.Y < -1) then
--Stops wallrun
end
currentTilt = currentTilt + (targetTilt - currentTilt) * 0.1
local camCF = CFrame.new(camera.CFrame.Position, camera.CFrame.Position + camera.CFrame.LookVector)
camCF = camCF * CFrame.Angles(0, 0, math.rad(currentTilt))
camera.CFrame = camCF
end)
video of the glitching: