i’m currently making a first person horror game but i have this problem with my first person crouch. If i crouch the camera is doing really weird. i can see my entire body but not my head and i dont know why its not working. Here is a video :2023-01-06 15-58-02. Any help is apriciated!
You can change the camera offset property in the humanoid by doing:
Humanoid.CameraOffset = Vector3.new() -- How many studs you want it to offset
So for the crouching you could use tween service & the camera offset to create a smooth transition from point a to point b:
local TweenService = game:GetService("TweenService")
...
TweenService:Create(Humanoid, TweenInfo.new(.5), { CameraOffset = Vector3.new(0,-1,0) }):Play() -- this would offset the camera by one studs going downwards
Then utilizing user input service, you can make them crouch every time they hold c or ctrl
Hi, srry for my late reply. I have to scripts. A crouch script and first person script.
First the first person script :
local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")
char.Humanoid.CameraOffset = Vector3.new(0, 0, -1)
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Head" then
v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
v.LocalTransparencyModifier = v.Transparency
end)
v.LocalTransparencyModifier = v.Transparency
end
end
RunService.RenderStepped:Connect(function(step)
local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
local ignoreList = char:GetChildren()
local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
if hit then
char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
else
char.Humanoid.CameraOffset = Vector3.new(0, 0, -1)
end
end)
Then crouch script :
-- config
local keybind = "C"
local animationId = 12069927446
--variables
local userInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://'.. animationId
local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action
local crouching = false
--functions
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode[keybind] then
if crouching then
humanoid.CameraOffset = Vector3.new(0,0,-1)
humanoid.WalkSpeed = 21
crouching = false
animationTrack:Stop()
character.HumanoidRootPart.CanCollide = true
else
humanoid.CameraOffset = Vector3.new(0,7,-1)
humanoid.WalkSpeed = 12
crouching = true
animationTrack:Play()
character.HumanoidRootPart.CanCollide = false
end
end
end)