Hello, I’m making a game like Criminality. At the moment, I’m working on the crouch mechanic but it needs some adjustments and it really should work better. I’m new to animations and animation priorities. So if you guys could help it would mean the world!
So right now my problem is:
When I hold C, the player crouches, when I start moving the player stops crouching and I need to press C *while walking if I want to walk-crouch.
The other problem I have is when I have a tool equipped the animation is played off the ground as if the tool is anchored. (I’m not sure if I need to set the hip height.)
Here is when I try to walk WHILE in crouch. And also crouch when I’m already walking.
Here is when I have a tool equipped when trying to crouch.
Overall the animation is stuttery, and also stops when I’m moving my camera around. Any help would be appreciated. Thanks!
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() or script.Parent
local hum = char:WaitForChild("Humanoid")
local sprintAnim = script:WaitForChild("Sprint")
local sprintTrack = hum:LoadAnimation(sprintAnim)
local crouchWalk = hum:LoadAnimation(script:WaitForChild("CrouchWalk"))
local crouch = hum:LoadAnimation(script:WaitForChild("CrouchIdle"))
local running = false
local crouching = false
--Sprint--
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift and hum.MoveDirection.Magnitude > 0 then
player.Character:WaitForChild("Humanoid").WalkSpeed = 30
sprintTrack:Play()
running = true
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
player.Character:WaitForChild("Humanoid").WalkSpeed = 10
sprintTrack:Stop()
running = false
end
end)
--Sprint--
--Crouch--
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C and running == false then
if hum.MoveDirection.Magnitude == 0 then
crouch:Play()
hum.WalkSpeed = 6
crouching = true
elseif hum.MoveDirection.Magnitude > 0 then
crouchWalk:Play()
hum.WalkSpeed = 6
crouching = true
end
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
crouchWalk:Stop()
crouch:Stop()
hum.WalkSpeed = 10
crouching = false
elseif running == true then
hum.WalkSpeed = 30
end
end)
--Crouch--
hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if hum.MoveDirection.Magnitude == 0 then
sprintTrack:Stop()
player.Character:WaitForChild("Humanoid").WalkSpeed = 10
elseif hum.MoveDirection.Magnitude > 0 and crouching == true then
crouchWalk:Play()
end
end)
Please stop posting your recruitment topic as your “signature”. It isn’t cool, just advertising. It actually draws people AWAY from it, so I see no benefit.