I’m trying to make a custom first person camera for this game I’m working on. the character dose not have a humanoid or a humanoidRootPart so I can’t just use roblox’s first person camera. I dont need anything with a whole lot of features just the core camera that can look around.
If you are able to help with this please do I have been looking for help for about 3 - 4 hours now
put this as a LocalScript inside StarterCharacterScripts and change the camera subject to whatever u want
local uis = game:GetService("UserInputService")
local ugs = UserSettings():GetService("UserGameSettings")
local cam = workspace.CurrentCamera
cam.CameraSubject = script.Parent:WaitForChild("Head")
local mobileDragging
local dragging
local distance = 0.5
cam.CameraType = Enum.CameraType.Scriptable
uis.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
dragging = true
end
if input.UserInputType == Enum.UserInputType.Touch then
mobileDragging = true
end
end)
uis.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
dragging = false
end
if input.UserInputType == Enum.UserInputType.Touch then
mobileDragging = false
end
end)
local camX,camY,camZ = cam.CFrame:ToEulerAnglesXYZ()
local xRot = 0
local yRot = 0
cam:GetPropertyChangedSignal("CFrame"):Connect(function()
for _,v:Instance in pairs(cam.CameraSubject.Parent:GetDescendants()) do
if (v:IsA("BasePart") or v:IsA("Decal") or v:IsA("Texture")) and not v:FindFirstAncestorOfClass("Tool") then
v.LocalTransparencyModifier = 1.5 - (distance / 2)
end
end
end)
game:GetService("RunService"):BindToRenderStep("Camera",0,function()
if distance <= 0.5 then
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
else
uis.MouseBehavior = Enum.MouseBehavior.Default
end
local mouseDelta = uis:GetMouseDelta()
local mouseSensitivity = ugs.MouseSensitivity
if uis.MouseBehavior == Enum.MouseBehavior.LockCenter then
dragging = false
end
if dragging or mobileDragging or uis.MouseBehavior ~= Enum.MouseBehavior.Default then
if dragging then
uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end
xRot += math.rad((mouseDelta.X*0.25)*mouseSensitivity * -1)
yRot += math.rad((mouseDelta.Y*0.25)*mouseSensitivity * -1)
end
yRot = math.clamp(yRot,math.rad(-75),math.rad(75))
cam.Focus = CFrame.new(cam.CameraSubject.Position)
cam.CFrame = cam.Focus
cam.CFrame *= CFrame.fromEulerAnglesYXZ(yRot, xRot, 0) * CFrame.new(0,0,distance)
end)