Hi, I made a crouch animation for a small FPS game I’m making, and it allows players to dodge shots easier, and get into smaller areas. I wanted to have the camera lower when you crouch, but I can’t figure it out.
The crouch animation looks like this, the camera stays in-place while the player’s body lowers, as demonstrated in the gif
This is also a problem when a player tries to crouch and crawl under objects, the camera clips through the object the player is under, like this:
Yes, but because StarterCharacterScripts just puts the script in the Character you can just do script.Parent:WaitForChild(“Humanoid”) or something like that.
Still trying to fix it, I haven’t any of my fixes to work. I tried taking lines of code from other scripts and putting it in mine, but it still won’t work. I might just keep it like this because it lowers the position of the player’s gun, allowing them to see more. If you have a solution for me, you can post it if you want to but I’m fine if you don’t. Thanks for trying to help and sending the developer link , I’ll to learn from the link and see if I can make the script work with the information it has.
Sorry I didnt see your response, basically in your code what you are doing is:
Define the Humanoid and UIS
Check when the player presses down a button
if its the left control key then
Wait for the Humanoid and get all children of the character (not sure why u are doing this)
set the Humanoids CameraOffset to its Offset + another 2 up and -1 on the z axis
else if it isnt the left control key then
wait for the humanoid (again not sure why)
set the Humanoids CamerOffset to its Offset + another 0.16 up and -1 on the z axis
This is what you want to do tho:
Define the UIS
Define the Humanoid
Check when the player presses down a button and if its the Left Control button
Set the Humanoids Offset to a Vector3 of ur choice like Vector3.new(0,-2,0) (this would move it down by 2 studs) instead of adding onto the current offset
Check when the player releases a button (InputEnded) and if its the Left Control button
Set the Humanoids CameraOffset back to Vector3.new(0,0,0)
In Code this would look something like this:
local UIS = game:GetService("UserInputService")
local HM = script.Parent:WaitForChild("Humanoid")
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.LeftControl then
HM.CameraOffset = Vector3(0,-2,0)
end
end)
UIS.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.LeftControl then
HM.CameraOffset = Vector3(0,0,0)
end
end)
I wouldn’t recommend doing it like this, because if the script somehow runs n times then your camera is going to move down 5 studs n times, instead you should just set the CameraOffset to a preset Vector (like in my reply)
Thank you so much for this. I’ll definitely take note of everything for the future. I changed the script a bit, and it works well. I’ll probably find a way to tween the camera so it isn’t too janky. Once again, thank you so much, I know it’s New Year’s and you probably didn’t have much time to do this, I’ll add your name in the credits of my game (unless you don’t want your name in the credits).
For anyone who wants the script, here it is. You’ll need to change the walkspeed and jump power after you stop crouching though. Change the cameraoffset if you need too. I could probably structure it better, too.
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local HUMAN = Character:WaitForChild("Humanoid")
local HM = script.Parent.Humanoid
local UIS = game:GetService("UserInputService")
local Animation = Instance.new("Animation")
local Stop = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://--insertanimationIDhere"
Animation.Parent = player.Character
Stop.AnimationId = "rbxassetid://insertanimationIDhere"
Stop.Parent = player.Character
local mouse = player:GetMouse()
local Animate
local debounce = false
UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.LeftControl then
wait(0.12)
if not debounce then
debounce = true
Animate = HUMAN:LoadAnimation(Animation)
Animate:Play()
HUMAN.WalkSpeed = HUMAN.WalkSpeed - 11
HUMAN.JumpPower = 0
HM.CameraOffset = Vector3.new(0,-0.8,-1)
else
Animate:Stop()
HM.CameraOffset = Vector3.new(0,0.18,-1)
HUMAN.WalkSpeed = 20
HUMAN.JumpPower = 26
debounce = false
end
end
end)
It uses a free script I modified a bit, I don’t know who originally made it but if I find out I’ll give credit. Make sure it’s a local script.it.
Also if you’re wondering why I was getting all the children, it’s because I copied and pasted some parts from the crouch animation script without second thought. I should really think before I copy stuff.