Buggy animations with directional walking system

Hey! So, for the record, I’m working on a directional walking system, and the one I have right now works just fine, but there are some problems while walking diagonally with the animations. Sometimes the animations overlap, and that’s exactly what I wanted because it’d look like the legs are walking diagonally, problem is, this bugs out at times and if a player starts walking mid animation, while the legs weren’t near the start or end of the animation, it’ll overlap and cause the animation to look like it’s jumping since both animations raise their legs at the same time.
This has happened to me before, when I used an open source directional walking system, but now I’m making my own, so I can get off the habit of looking for scripts that are pre-made and make my own.

I’ve tried to make the FadeTime of the animations be how many seconds are left for the walking forward animations to finish, with this line:
local duration = animations_table.WalkForward.Length - animations_table.WalkForward.TimePosition
but that didn’t work, it really just caused more problems than anything…

Example of the problem:

Script I’m using (I know it’s kind of messy the way I did it, but I’ll get to fixing that in a bit, now I’m just trying to fixing this bug done…)

-- // SERVICES \\ --
local user_input_ser = game:GetService("UserInputService")
local rep_ser = game:GetService("ReplicatedStorage")
local run_ser = game:GetService("RunService")

-- // INSTANCES \\ --
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local hum = chr:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local root_part = chr:WaitForChild("HumanoidRootPart")


-- // ANIMATIONS \\ --
local animations_folder = script:WaitForChild('Animations')
local animations_table = {
	WalkForward = hum:LoadAnimation(animations_folder.WalkForward),
	WalkLeft = hum:LoadAnimation(animations_folder.WalkLeft),
	WalkRight = hum:LoadAnimation(animations_folder.WalkRight),
	Running = hum:LoadAnimation(animations_folder.Running),
	Jump = hum:LoadAnimation(animations_folder.Jump),
	Fall = hum:LoadAnimation(animations_folder.Fall)
}

for i, anim in pairs(animations_table) do
	anim:Play(0,0,0)
end

run_ser.RenderStepped:Connect(function()
	local movement_direction = root_part.CFrame:VectorToObjectSpace(root_part.AssemblyLinearVelocity)
	
	local forward = math.abs(math.clamp(movement_direction.Z / hum.WalkSpeed, -1, -0.001))
	local backward = math.abs(math.clamp(movement_direction.Z / hum.WalkSpeed, 0.001, 1))
	local left = math.abs(math.clamp(movement_direction.X / hum.WalkSpeed, -1, -0.001))
	local right = math.abs(math.clamp(movement_direction.X / hum.WalkSpeed, 0.001, 1))
	
	local duration = animations_table.WalkForward.Length - animations_table.WalkForward.TimePosition
	
	if forward > 0.4 then
		if animations_table.WalkForward.IsPlaying == false then
			animations_table.WalkForward:Play(0.1)
		end
	end
	
	if forward < 0.4 then
		if animations_table.WalkForward.IsPlaying == true then
			animations_table.WalkForward:Stop(0.1)
		end
	end
	
	if right > 0.4 then
		if animations_table.WalkRight.IsPlaying == false then
			animations_table.WalkRight:Play(duration)
		end
	end

	if right < 0.4 then
		if animations_table.WalkRight.IsPlaying == true then
			animations_table.WalkRight:Stop(0.1)
		end
	end
	
	if left > 0.4 then
		if animations_table.WalkLeft.IsPlaying == false then
			animations_table.WalkLeft:Play(duration)
		end
	end

	if left < 0.4 then
		if animations_table.WalkLeft.IsPlaying == true then
			animations_table.WalkLeft:Stop(0.1)
		end
	end
end)

I’m not looking for entire scripts to fix this, and instead maybe a suggestion to guide me to fixing this!

5 Likes

Bump, I haven’t been able to find any solution yet…!

3 Likes

maybe try making it continue using the foward walk animation but rotating the motor6d until it surpasses a threshold, then switch to the side walking

2 Likes

I’m not sure how I’d get about that… I just tried using lerping, but I couldn’t get it to work very well.

2 Likes

it isn’t exactly hard, but you would need find the relative rotation from where you moving to and from the torso, i have a script I made that takes care of that but I cannot show it as I don’t have access currently

1 Like

Hmm… couldn’t I try to use the movedirection for that?

1 Like

technically yea, but movedirection is world, you would need turn that into relative, idk if making it a cframe and multiplying by the character angle would work, but it’s worth a shot

1 Like

Wait can’t I just use this? local movement_direction = root_part.CFrame:VectorToObjectSpace(root_part.AssemblyLinearVelocity) it’s just a line I already had in the code

2 Likes

I guess? I haven’t messed around with cframe methods yet but it should

1 Like

I can’t exactly figure out how to make this, I’ll be honest, I have no clue, lol

1 Like

I think it’s because the animation are overlapping
try to set the forward, backward animation priority to Action1
and then set the left and right animation priority to Action2.

1 Like