In my game (where the camera is locked to first person), I made the player have the ability to crouch, but the camera isn’t staying in the character’s head when the animation plays. Is there any way to move the camera into the head instead of the humanoid root part somehow? I have tried changing the player’s camera subject to their head, but that ends up making the player unable to turn their character and makes all of their accessories block their camera.
Here’s my code if you need it:
local Camera = workspace:WaitForChild("Camera")
local Player = game:GetService("Players").LocalPlayer
Player.CameraMode = Enum.CameraMode.LockFirstPerson
local Head = script.Parent:WaitForChild("Head")
Camera.CameraSubject = Head
Here is a way to do it, it can be more efficient for sure and also could use a lerp to make it smooth.
local Camera = workspace:WaitForChild("Camera")
local Player = game:GetService("Players").LocalPlayer
Player.CameraMode = Enum.CameraMode.LockFirstPerson
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
if keyPressed == Enum.KeyCode.C then -- Crouch key
game.Players.LocalPlayer.Character.Humanoid.CameraOffset=Vector3.new(0,-2,0)
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
if keyPressed == Enum.KeyCode.C then -- Crouch key
game.Players.LocalPlayer.Character.Humanoid.CameraOffset=Vector3.new(0,0,0)
end
end
end)