Hey guys. I have 2 scripts that arent working together. I think I know the reason but I just dont know how to fix it.
I have a script that makes first person look “realistic”. It also makes the mouse movement smoother in a sense that it delays the mouse movement by a bit. I think this script is overriding my sway camera script leading it to not work. I will provide videos of what both scripts do, then provide the scripts.
Note: In my first person script im also controlling something i have called interactables. Just skip over that.
Realistic First Person:
Camera Sway:
Realistic First Person Script(the part that needed fixing):
RS.RenderStepped:connect(function()
if _G.booted == false then
cam.CFrame = workspace.CamPart.CFrame
return
end
if running then
updatechar()
CamPos = CamPos + (TargetCamPos - CamPos) *0.28
AngleX = AngleX + (TargetAngleX - AngleX) *0.35
local dist = TargetAngleY - AngleY
dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
AngleY = (AngleY + dist *0.35) %360
cam.CameraType = Enum.CameraType.Scriptable
cam.CoordinateFrame = CFrame.new(head.Position.X, head.Position.Y + 0.1, head.Position.Z)
* CFrame.Angles(0,math.rad(AngleY),0)
* CFrame.Angles(math.rad(AngleX),0,0)
* CFrame.new(0,0.5,0) -- offset
humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
end
if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
running = false
else
running = true
--if freemouse == true then
-- game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
--else
-- game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
--end
end
--cam.CFrame = char.Head.CFrame
--if not CanToggleMouse.allowed then
-- freemouse = false
--end
--cam.FieldOfView = FieldOfView
end)
Camera Sway Script:
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Turn = 0
local Lerp = function(a, b, t)
return a + (b - a) * t
end;
RunService:BindToRenderStep("CameraSway", Enum.RenderPriority.Camera.Value + 1, function(deltaTime)
local MouseDelta = UserInputService:GetMouseDelta()
Turn = Lerp(Turn, math.clamp(MouseDelta.X, -3, 3), (3 * deltaTime))
Camera.CFrame = Camera.CFrame * CFrame.Angles(0, 0, math.rad(Turn))
end)