Im assuming it has something to do with the camera position when the root part of the character moves. Apart from that I made this script because I wanted to make a custom First person script. I am honestly stuck, and all help is appreciated.
Local Script:
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local X, Y, AngleX, AngleY = 0,0, CFrame.Angles(0,0,0), CFrame.Angles(0,0,0) -- Base values
local Camera = workspace.CurrentCamera
local Offset = CFrame.new(0, 0.25, 1.25) * CFrame.Angles(0, math.rad(180), 0) -- You might want to change this to suit your game better
function Update()
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
Camera.CameraType = Enum.CameraType.Scriptable
local Delta = UIS:GetMouseDelta() -- Get change in mouse position
X = X + (Delta.X*0.15) -- Set X value accordingly (mouse left/right)
Y = math.clamp(Y + (Delta.Y*0.15),-89.99,89.99) -- Set value Y value accordingly (mouse up/down, clamped to prevent glitch where camera rotates at 90)
AngleX = CFrame.Angles(0, math.rad(-X), 0) -- Create angles using X on Y
AngleY = CFrame.Angles(math.rad(-Y),0,0) -- Create angles using Y on X
Camera.CFrame = CFrame.new((Char.Head.CFrame).p) * AngleX * Offset * AngleY
local Position = Char.HumanoidRootPart.CFrame.p -- Set to the root part's position
local GoalRotate = CFrame.new(Position, Camera.CFrame.Position) -- Faces the camera from the root part's position
local _, RotY, _= GoalRotate:ToOrientation() -- Stores the Y orientation value, which we will then use in CFrame.fromOrientation to set the X and Z to 0, limiting it to Y (rotating side to side)
Char.HumanoidRootPart.CFrame = CFrame.new(Position) * CFrame.fromOrientation(0, RotY, 0)
end
game:GetService("RunService"):BindToRenderStep("Update",Enum.RenderPriority.Camera.Value, Update) -- Use BindToRenderStep so it updates compared to Roblox's default camera