Hey, im using this script to attach the camera to the head, but i have one problem, when i move the camera around, the body does not rotate with the camera (as it would do on first person or shiftlock) the CameraMode is set to LockFirstPerson and it still doesnt work.
Heres the code!
local RunService = game:GetService("RunService")
local InputService = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.AutoRotate = false
local CurrentCamera = workspace.Camera
CurrentCamera.CameraType = Enum.CameraType.Scriptable
local Head = Character:WaitForChild("Head")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local CameraRotation = Vector2.new(0, 0)
local RotationSpeed = Vector2.new(1, 1)
local BodyRotationSpeed = 10
local SmoothnessFactor = 0.1
for _, part in ipairs(Character:GetChildren()) do
if part:IsA("BasePart") and not (part.Name:match("Arm") or part.Name:match("Torso") or part.Name:match("Leg")) then
part.Transparency = 1
part.CanCollide = false
elseif part:IsA("Accessory") then
part:Destroy()
end
end
InputService.InputChanged:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseMovement then
CameraRotation += Vector2.new(Input.Delta.X * -1, Input.Delta.Y * -1) * RotationSpeed
CameraRotation = Vector2.new(CameraRotation.X, math.clamp(CameraRotation.Y, -80, 80))
end
end)
RunService.RenderStepped:Connect(function()
InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local targetCameraRotation = Vector2.new(CameraRotation.X, CameraRotation.Y)
CameraRotation = CameraRotation:Lerp(targetCameraRotation, SmoothnessFactor)
local HorizontalAngle = math.rad(CameraRotation.X)
local VerticalAngle = math.rad(CameraRotation.Y)
CurrentCamera.CFrame = Head.CFrame * CFrame.fromEulerAnglesYXZ(VerticalAngle, HorizontalAngle, 0)
if HumanoidRootPart then
local direction = Vector3.new(math.sin(HorizontalAngle), 0, math.cos(HorizontalAngle))
HumanoidRootPart.CFrame = CFrame.lookAt(HumanoidRootPart.Position, HumanoidRootPart.Position + direction)
end
end)
You’re using the head to “localize” the camera CFrame. But then you want to move the HRP with respect to the camera rotation. The HRP then rotates the head, resulting in a kind of infinite rotation when I tried to set the HRP cframe to the camera cframe look vector.
Here’s what I changed that worked:
RunService.RenderStepped:Connect(function()
InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local targetCameraRotation = Vector2.new(CameraRotation.X, CameraRotation.Y)
CameraRotation = CameraRotation:Lerp(targetCameraRotation, SmoothnessFactor)
local HorizontalAngle = math.rad(CameraRotation.X)
local VerticalAngle = math.rad(CameraRotation.Y)
local new_camera_cf = CFrame.fromEulerAnglesYXZ(VerticalAngle, HorizontalAngle, 0) + Head.CFrame.Position
CurrentCamera.CFrame = new_camera_cf
if HumanoidRootPart then
local direction = Vector3.new(new_camera_cf.LookVector.X, 0, new_camera_cf.LookVector.Z)
HumanoidRootPart.CFrame = CFrame.lookAlong(HumanoidRootPart.Position, direction, Vector3.yAxis)
end
end)
so you want the camera and head to be the same cframe?
Then you’re getting into trying to take over the Neck Motor6D inside of Head.
The animator generally controls that.
If you create a blank localscript called “Animate” inside of StarterCharacterScripts it will remove all default animations. Then just set StarterPlayer.CameraMode to LockFirstPerson. No programming required.