Hello! I am currently trying to implement an eight way walk system into a script, however for some reason “ForwardRight” cannot be detected and won’t be printed. Can someone help me out?
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRoot = Character:WaitForChild("HumanoidRootPart")
-----AnimationHandler
local Animate = script
local RelativeWalk = script:WaitForChild("RelativeWalk")
local animback = Humanoid:LoadAnimation(script.RelativeWalk:FindFirstChild("WalkAnimBack"))
local animfront = Humanoid:LoadAnimation(script.RelativeWalk:FindFirstChild("WalkAnimFront"))
local animleft = Humanoid:LoadAnimation(script.RelativeWalk:FindFirstChild("WalkAnimLeft"))
local animright = Humanoid:LoadAnimation(script.RelativeWalk:FindFirstChild("WalkAnimRight"))
local animidle = Humanoid:LoadAnimation(script.RelativeWalk:FindFirstChild("WalkAnimIdle"))
---Animations' Names
local WalkF = RelativeWalk.WalkAnimFront
local WalkB = RelativeWalk.WalkAnimBack
local WalkR = RelativeWalk.WalkAnimRight
local WalkL = RelativeWalk.WalkAnimLeft
-----Varibles
local RunSer = game:GetService("RunService")
--(*)
local CurrentAnim = nil
-----Functions^^}
function ToWalkRelativeToHRP(Humanoid, Direction, RootCompare)
-----Check if player is moving
if Direction ~= nil then
----X-x-x Continue
local RootFacing = RootCompare.CFrame.LookVector
local RootRight = RootCompare.CFrame.RightVector
local DirectionRelativeToRootFront = RootFacing:Dot(Direction, RootFacing)
local DirectionRelativeToRootSides = RootRight:Dot(Direction, RootRight)
----
local Output = nil
if DirectionRelativeToRootFront <= 1 and DirectionRelativeToRootFront >= 0.75 then
Output = "Forwards"
elseif DirectionRelativeToRootFront >= -1 and DirectionRelativeToRootFront <= -0.75 then
Output = "Backwards"
elseif DirectionRelativeToRootSides <= 1 and DirectionRelativeToRootSides >= 0.75 then
Output = "Right"
elseif DirectionRelativeToRootSides >= -1 and DirectionRelativeToRootSides <= -0.75 then
Output = "Left"
elseif DirectionRelativeToRootFront <= 1 and DirectionRelativeToRootSides >= 0.75 then
Output = "ForwardsRight" -- cannot be detected for some reason
end
return Output
end
end
----------Below heres is not needed but just shows the ways you could use it!
RunSer.RenderStepped:Connect(function()
local ForceVector = ToWalkRelativeToHRP(Humanoid, Humanoid.MoveDirection, HumanoidRoot)
print(ForceVector)
if ForceVector == "Forwards" then
script.WalkDirection.Value = "Forward"
elseif ForceVector == "Backwards" then
script.WalkDirection.Value = "Backward"
elseif ForceVector == "Right" then
script.WalkDirection.Value = "Right"
elseif ForceVector == "Left" then
script.WalkDirection.Value = "Left"
elseif ForceVector == nil then
script.WalkDirection.Value = "Idle"
elseif ForceVector == "ForwardRight" then
script.WalkDirection.Value = "ForwardRight"
end
end)