Animation jerks when walking in a crouch

Hello everyone, I’m making crouch system. I use two animations first animation when the player is crouched and does nothing and the other when the player moves. Right now the problem is happening with the walking animation. When the player moves the animation jerks and it looks very strange. Here is the video and script:

local KeyBind = "LeftControl"

local UIS = game:GetService("UserInputService")
local Tween = game:GetService("TweenService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = script:WaitForChild("CrouchIdle")
local Animation2 = script:WaitForChild("CrouchWalk")
local TrackAnim = Humanoid:LoadAnimation(Animation)
local TrackAnim2 = Humanoid:LoadAnimation(Animation2)
TrackAnim.Looped = true
TrackAnim2.Looped = true

local Crouching = false

UIS.InputBegan:Connect(function(Input, GPE)
	if GPE then return end
	
	if Input.KeyCode == Enum.KeyCode[KeyBind] then
		if Crouching then
			Humanoid.WalkSpeed = 8
			Crouching = false
			Character:WaitForChild("HumanoidRootPart").CanCollide = true
			Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, 0, 0)}):Play()
			script.Parent:WaitForChild("Sprint").Enabled = true
			
			TrackAnim:Stop()
		else
			Humanoid.WalkSpeed = 5
			Crouching = true
			Character:WaitForChild("HumanoidRootPart").CanCollide = false
			Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, -1.75, 0)}):Play()
			script.Parent:WaitForChild("Sprint").Enabled = false
			Tween:Create(game.Players.LocalPlayer.Character.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {WalkSpeed = 5}):Play()

			Tween:Create(workspace.CurrentCamera, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {FieldOfView = 70}):Play()
			
			Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
				if Humanoid.MoveDirection.Magnitude > 0 and Crouching == true then
					TrackAnim2:Play()
				else
					TrackAnim2:Stop()
				end
			end)
			TrackAnim:Play()
			TrackAnim:AdjustSpeed(0.8)
		end
	end
end)
7 Likes

Maybe the 2 animations (your own walk anim and robloxs default walk anim) are blending in together? if it is, try Adjusting The Weight and chaging the Animation Priority to Movement.

4 Likes

AdjustWeight didn’t help. The first animation has priority Action and the second one Action2. But i try change second animation priority to movement

4 Likes

What weight did you set the anims to?

4 Likes

Didn’t help, the animation still jerks

4 Likes

First animation have 1 weight, second animation have 3 weight

4 Likes

Make the idle anim have the weight of 30 and the walk anim 31? It needs to be a high number.

4 Likes

Still didn’t help. I don’t understand why this happens

4 Likes

Can you send me the animation ID’s please? Im gonna try to find a solution on roblox studio.

3 Likes

17038831014: Idle
17038941012: Movement

4 Likes

Thanks. I will tell you if i find a solution.

5 Likes

Also what is the local scripr called “Sprint” thats in the character?
resim_2024-04-07_120203368

4 Likes

When a player crouches, the sprint script is turned off, so that the crouched player does not run

4 Likes

I think i found the problem. The walk anim plays again if you change the direction of where youre walking to another direction.

4 Likes

how does it get fixed?(30 chaaar)

4 Likes

I think you can change the walking animation in the animate script inside the character?

5 Likes

You should change these 2 with your own animation. I will try to add this into your script.
resim_2024-04-07_120900305

4 Likes

Okay, I’ll change their ID in script

4 Likes

I did it but there are some couple bugs. (also og walk og run, oganimation1 and oganimation2 original anims. oganimation1 is animation1 under idle inside the animate script and oganimation2 is animation 2 under idle.)

local KeyBind = "LeftControl"

local UIS = game:GetService("UserInputService")
local Tween = game:GetService("TweenService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Animate = Character:WaitForChild("Animate")
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = script:WaitForChild("CrouchIdle")
local Animation2 = script:WaitForChild("CrouchWalk")
local OgWalk = script:WaitForChild("OgWalk")
local OgRun = script:WaitForChild("OgRun")
local TrackAnim = Humanoid:LoadAnimation(Animation)
local TrackAnim2 = Humanoid:LoadAnimation(Animation2)
TrackAnim.Looped = true
TrackAnim2.Looped = true

local Crouching = false

UIS.InputBegan:Connect(function(Input, GPE)
	if GPE then return end

	if Input.KeyCode == Enum.KeyCode[KeyBind] then
		if Crouching then
			Animate.idle.Animation1.AnimationId = script.OgAnimation1.AnimationId
			Animate.idle.Animation2.AnimationId = script.OgAnimation2.AnimationId
			Animate.run.RunAnim.AnimationId = OgRun.AnimationId
			Animate.walk.WalkAnim.AnimationId = OgWalk.AnimationId
			Humanoid.WalkSpeed = 8
			Crouching = false
			Character:WaitForChild("HumanoidRootPart").CanCollide = true
			Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, 0, 0)}):Play()
		else
			Animate.idle.Animation1.AnimationId = Animation.AnimationId
			Animate.idle.Animation2.AnimationId = Animation.AnimationId
			Animate.run.RunAnim.AnimationId = Animation2.AnimationId
			Animate.walk.WalkAnim.AnimationId = Animation2.AnimationId
			Humanoid.WalkSpeed = 5
			Crouching = true
			Character:WaitForChild("HumanoidRootPart").CanCollide = false
			Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, -1.75, 0)}):Play()
			Tween:Create(game.Players.LocalPlayer.Character.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {WalkSpeed = 5}):Play()

			Tween:Create(workspace.CurrentCamera, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {FieldOfView = 70}):Play()
			
			
			TrackAnim:AdjustSpeed(0.8)
		end
	end
end)
6 Likes

oganim1 is

http://www.roblox.com/asset/?id=180435571

oganim2 is

http://www.roblox.com/asset/?id=180435792

ogwalk is

http://www.roblox.com/asset/?id=180426354

and ogrun is

http://www.roblox.com/asset/?id=180426354
3 Likes