Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ⬇️ LocalScript inside StarterPlayerScripts or StarterCharacterScripts
- local RunService = game:GetService("RunService")
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local camera = workspace.CurrentCamera
- --------------------------------------------------------------------
- -- CONFIG ----------------------------------------------------------
- --------------------------------------------------------------------
- local offset = CFrame.new(0, 0, -1.5) -- change Z to pull back / Y to raise or lower
- local bindName = "CustomFPSCam" -- render-step binding name
- --------------------------------------------------------------------
- --------------------------------------------------------------------
- -- 1) Make body parts stay visible in first-person
- --------------------------------------------------------------------
- local function forceBodyVisible(character)
- for _, part in ipairs(character:GetDescendants()) do
- if part:IsA("BasePart") and part.Name ~= "Head" then
- part.LocalTransparencyModifier = part.Transparency
- part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
- part.LocalTransparencyModifier = part.Transparency
- end)
- end
- end
- end
- --------------------------------------------------------------------
- -- 2) Attach camera to CameraRigPart each frame
- --------------------------------------------------------------------
- local function followCamPart(character, camPart)
- -- Ensure only one render-step connection is running
- RunService:UnbindFromRenderStep(bindName)
- RunService:BindToRenderStep(bindName, Enum.RenderPriority.Camera.Value, function()
- if not camPart.Parent then return end
- -- Desired camera frame (eye point) = camPart + offset
- local desiredCF = camPart.CFrame * offset
- -- (Optional) very simple anti-clip test
- local params = RaycastParams.new()
- params.FilterDescendantsInstances = { character }
- params.FilterType = Enum.RaycastFilterType.Blacklist
- local rayDir = desiredCF.Position - camPart.Position
- local result = workspace:Raycast(camPart.Position, rayDir, params)
- if result then -- if a wall is in the way, stop before it
- desiredCF = CFrame.new(result.Position)
- end
- camera.CFrame = desiredCF
- end)
- end
- --------------------------------------------------------------------
- -- 3) Main setup per character spawn / respawn
- --------------------------------------------------------------------
- local function setupCharacter(character)
- forceBodyVisible(character)
- -- Don’t let Humanoid.CameraOffset fight us
- local hum = character:WaitForChild("Humanoid", 5)
- if hum then hum.CameraOffset = Vector3.new() end
- -- Wait for your custom camera part
- local camPart = character:WaitForChild("CameraRigPart", 5)
- if not camPart then
- warn("CameraRigPart not found in character!")
- return
- end
- -- Give full control to the script
- camera.CameraType = Enum.CameraType.Scriptable
- followCamPart(character, camPart)
- end
- --------------------------------------------------------------------
- -- 4) Hook into current & future spawns
- --------------------------------------------------------------------
- if player.Character then
- setupCharacter(player.Character)
- end
- player.CharacterAdded:Connect(setupCharacter)
- --------------------------------------------------------------------
- -- 5) Optional: lock mouse to centre & hide cursor
- --------------------------------------------------------------------
- -- game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
- -- game:GetService("UserInputService").MouseIconEnabled = false
Advertisement
Add Comment
Please, Sign In to add comment