So I'm working on a Animate script that will hopefully have 8 different animations for all 8 directions. Aka up, down, left, right, up right, up left, down right, and down left. Pretty simple on paper but I'm struggling with understanding concepts like :AdjustWeight and other animation gimmicks. Was wondering if someone could help me figure out a way to make the script without have a mish-mash of conditions and exceptions.
What I have right now is this which I borrowed from another post about a similar topic. But sadly it only handles 4 directions(up,down,left,right) and I'm trying to see if I can make it handle 8 instead
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local agility = character:WaitForChild("Agility")
local UIS = game:GetService("UserInputService")
script:WaitForChild("leftwalk"):WaitForChild("Animation")
local currently_playing_anim = {}
local anim = {
["frontrun"]=humanoid:LoadAnimation(script.Movement.run.Animation);
["frontwalk"]=humanoid:LoadAnimation(script.Movement.walkA0.Animation);
["frontrightwalk"]=humanoid:LoadAnimation(script.Movement.walkA2.Animation);
["frontleftwalk"]=humanoid:LoadAnimation(script.Movement.walkA1.Animation);
["rightwalk"]=humanoid:LoadAnimation(script.Movement.walkA4.Animation);
["leftwalk"]=humanoid:LoadAnimation(script.Movement.walkA3.Animation);
["backrightwalk"]=humanoid:LoadAnimation(script.Movement.walkA6.Animation);
["backleftwalk"]=humanoid:LoadAnimation(script.Movement.walkA5.Animation);
["backwalk"]=humanoid:LoadAnimation(script.Movement.walkA7.Animation)
}
local X,Z = 0,0
for i,v in pairs(anim) do
v:Play()
v.Looped = true
end
local function setallweight(num)
for i,v in pairs(anim) do
v:AdjustWeight(num)
end
end
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
anim["backwalk"]:AdjustSpeed(humanoid.WalkSpeed/10)
anim["frontwalk"]:AdjustSpeed(humanoid.WalkSpeed/10)
anim["frontrun"]:AdjustSpeed(humanoid.WalkSpeed/25)
end)
game:GetService("RunService").RenderStepped:Connect(function()
local movedir = character.PrimaryPart.CFrame:vectorToObjectSpace(humanoid.MoveDirection)
local currentstate = humanoid:GetState()
X = movedir.X
Z = movedir.Z
local distZ,distZMin = ((character.PrimaryPart.CFrame.LookVector * 5) - Vector3.new(0,0,Z)).Magnitude,((character.PrimaryPart.CFrame.LookVector * -5) - Vector3.new(0,0,Z)).Magnitude
--print("X = "..movedir.X.." Z = "..movedir.Z)
if currentstate == Enum.HumanoidStateType.Jumping then
setallweight(0)
elseif currentstate == Enum.HumanoidStateType.Freefall then
setallweight(0)
else
if Z == 0 then
anim["backwalk"]:AdjustWeight(0)
anim["frontwalk"]:AdjustWeight(0)
anim["frontrun"]:AdjustWeight(0)
elseif Z < 0 then
anim["backwalk"]:AdjustWeight(0)
humanoid.WalkSpeed = agility.Value
if humanoid.WalkSpeed < 20 then
anim["frontwalk"]:AdjustWeight((Z*-1.1)-((agility.Value/10)-1))
anim["frontrun"]:AdjustWeight((agility.Value/10)-1)
else
anim["frontrun"]:AdjustWeight(Z*-1.1)
anim["frontwalk"]:AdjustWeight(1-((agility.Value/10)-1))
end
elseif Z > 0 then
anim["backwalk"]:AdjustWeight(Z*1.1)
anim["frontrun"]:AdjustWeight(0)
anim["frontwalk"]:AdjustWeight(0)
humanoid.WalkSpeed = agility.Value/2
end
if X == 0 then
anim["rightwalk"]:AdjustWeight(0)
anim["leftwalk"]:AdjustWeight(0)
elseif X < 0 and not UIS:IsKeyDown(Enum.KeyCode.W) and not UIS:IsKeyDown(Enum.KeyCode.S) then
anim["rightwalk"]:AdjustWeight(X*-1.2)
anim["leftwalk"]:AdjustWeight(0)
--print(X*-1.2)
elseif X > 0 and not UIS:IsKeyDown(Enum.KeyCode.W) and not UIS:IsKeyDown(Enum.KeyCode.S) then
anim["rightwalk"]:AdjustWeight(0)
anim["leftwalk"]:AdjustWeight(X*1.2)
--print(X*1.2)
elseif X > 0 and Z > 0 then
anim["rightwalk"]:AdjustWeight(0)
anim["leftwalk"]:AdjustWeight(X*0.4)
elseif X > 0 and Z < 0 then
anim["rightwalk"]:AdjustWeight(0)
anim["leftwalk"]:AdjustWeight(X*0.4)
elseif X < 0 and Z > 0 then
anim["rightwalk"]:AdjustWeight(X*-0.4)
anim["leftwalk"]:AdjustWeight(0)
elseif X < 0 and Z < 0 then
anim["rightwalk"]:AdjustWeight(X*-0.4)
anim["leftwalk"]:AdjustWeight(0)
end
end
end)
