How to implement sideways walking and backwards walking using Roblox's default animation script?

I’ve got the idle and front walking animation working all right, I have absolutely no clue how to make it walk sideways or backwards.

Was following this guys tutorial. https://www.youtube.com/watch?v=rplF-mKRX2A
You can see around 2:00 he has sideways walking. Not sure how he did this with the default animation script.

EDIT: I’ve been told I’m probably going to have to make my own animation script for this, however, if anyone has any ideas how to incorporate it into the default roblox animation script please shoot it at me because animations scripts are hard to make lol.

4 Likes

Hi there i’ve made a way to do this, try it out and see if it works well because i’m not sure
Anyways let’s start by getting the direction the player is moving.
To do that we check the Humanoid MoveDirection relative to the Camera LookVector and RightVector using DotProduct. We know that 2 vectors are equal if the dot product is 1 so applying that we can say if : the DotProduct of MoveDirection and camera’s RightVector is close to 1 then the player is moving right.
Now we just update the animation ID inside of the default Animate script.
Anyway the code will look like this :

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	-- Update the Animations every time the player moves
	local DirectionRight = Humanoid.MoveDirection:Dot(Camera.CFrame.RightVector)
	local DirectionFront = Humanoid.MoveDirection:Dot(Camera.CFrame.LookVector)
	if DirectionRight > 0.8 or DirectionRight < - 0.8  then -- Moving Sideways
		character.Animate.run.RunAnim.AnimationId = "" 
	end
	
	if DirectionFront > 0.8 then   --Moving Forward
		character.Animate.run.RunAnim.AnimationId = ""
	elseif DirectionFront < - 0.8 then  --Moving Backwards
		character.Animate.run.RunAnim.AnimationId = ""
	end

end)	
4 Likes

Hi, thank you for your response. I’ll try it out and let you know if it works!

1 Like

It works! The only problem is sometimes it has some difficulty switching to the next animation as you can see in the video. Is there any way to fix this?

1 Like

I’m not entirely sure how to fix that but we can try some things

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	-- Update the Animations every time the player moves
	local DirectionRight = Humanoid.MoveDirection:Dot(Camera.CFrame.RightVector)
	local DirectionFront = Humanoid.MoveDirection:Dot(Camera.CFrame.LookVector)
	if DirectionRight > 0.8 or DirectionRight < - 0.8  then -- Moving Sideways
		if character.Animate.run.RunAnim.AnimationId == "" then return end
		character.Animate.run.RunAnim.AnimationId = "" 
	end
	
	if DirectionFront > 0.8 then   --Moving Forward
		if character.Animate.run.RunAnim.AnimationId == "" then return end
		character.Animate.run.RunAnim.AnimationId = ""
	elseif DirectionFront < - 0.8 then  --Moving Backwards
		if character.Animate.run.RunAnim.AnimationId == "" then return end
		character.Animate.run.RunAnim.AnimationId = ""
	end

end)

Let’s limit the amount of times the animation changes

2 Likes

Unfortunately that didn’t fix it but thanks for trying!

yea I figured out the issue so i’m look for a fix the problem is that even tho the animation updates the Animate script will only change it once the previous one fully ends

I just couldn’t get it to work the Animate script is just not made to update that fast i guess.
So i made it custom

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local ForwardAnim = Humanoid.Animator:LoadAnimation(script:WaitForChild("Forward"))
local BackwardsAnim = Humanoid.Animator:LoadAnimation(script:WaitForChild("Backwards"))
local SideAnim = Humanoid.Animator:LoadAnimation(script:WaitForChild("Side"))

local function StopAnims()
	ForwardAnim:Stop()
	BackwardsAnim:Stop()
	SideAnim:Stop()
end

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	
	if Humanoid.MoveDirection.Magnitude < 0.1 then
		StopAnims()
		return
	end
	
	local DirectionRight = Humanoid.MoveDirection:Dot(Camera.CFrame.RightVector)
	local DirectionFront = Humanoid.MoveDirection:Dot(Camera.CFrame.LookVector)
	if DirectionRight > 0.8 or DirectionRight < - 0.8  then -- Moving Sideways
		if SideAnim.IsPlaying then return end
		StopAnims()
		SideAnim:Play(.2)
	 	
	end
	
	if DirectionFront > 0.8 then   --Moving Forward
		if ForwardAnim.IsPlaying then return end
		StopAnims()
		ForwardAnim:Play(.2)
		
	elseif DirectionFront < - 0.8 then  --Moving Backwards	
		if BackwardsAnim.IsPlaying then return end
		StopAnims()
		BackwardsAnim:Play(.2)
	end

end)

Try this out if it doesn’t work increase your animations priorities to Movement or Action it should work.
Hope this helped

2 Likes

Thank you so much! It works super well now and is very responsive.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.