local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local PS = game:GetService("Players")
local Player = PS.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local HRP = Char:FindFirstChild("HumanoidRootPart") or Char:WaitForChild("HumanoidRootPart")
local Humanoid = Char.Humanoid or Char:WaitForChild("Humanoid")
local Mouse = Player:GetMouse()
local Camera = game.Workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
local MouseLocked = true
Humanoid.AutoRotate = false
local AngleX = 0
local AngleY = 0
local TransparencyTable = {}
for I, V in pairs(Char:GetDescendants()) do
if V:IsA("BasePart") then
TransparencyTable[V] = V.Transparency
elseif V:IsA("Accessory") then
for I, Child in pairs(V:GetChildren()) do
TransparencyTable[V] = {}
TransparencyTable[V][Child] = Child.Transparency
end
end
end
UIS.InputChanged:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseMovement then
local Change = Vector2.new(Input.Delta.x/0.8, Input.Delta.y/0.8) * 0.3
local X = AngleX - Change.y
AngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
AngleY = (AngleY - Change.x)
end
end)
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.F then
if MouseLocked == true then
MouseLocked = false
else
MouseLocked = true
end
end
end)
local function UpdateTransparency ()
for I, V in pairs(Char:GetChildren()) do
if V:IsA("BasePart") and V.Name == "Head" then
V.Transparency = 1
V.face.Transparency = 1
elseif V:IsA("Accessory") then
for I, Child in pairs(V:GetChildren()) do
Child.Transparency = 1
end
end
end
end
RS.RenderStepped:Connect(function()
UpdateTransparency()
local CameraPosition = Char.Head.Position + Vector3.new(0, 0.7, -0.7)
Camera.CFrame = CFrame.new(CameraPosition) * CFrame.Angles(0, math.rad(AngleY), 0) * CFrame.Angles(math.rad(AngleX), 0, 0)
HRP.CFrame = CFrame.new(HRP.Position)*CFrame.Angles(0,math.rad(AngleY),0)
if MouseLocked == true then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
else
UIS.MouseBehavior = Enum.MouseBehavior.Default
end
end)
thats the code for the first person camera im trying to make. for some reason its not working as intended. it would be great if you can test it and tell me the problem
you can see the problem clearer if you look down and try to spin/look around while looking down you will be able to see that the camera is positioned/acts weird
im not tryna copy someones code so it would be nice if you can explain the problem and the way to solve and not just give me the right code as im tryna learn