Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to change the walking animation related to the direction?

Asked by 4 years ago

Ill make it simple: I want to make the character play a certain walking animation when going forward and another when going backwards, this is what i've tried so far:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local Camera = workspace.CurrentCamera
local Result = Camera.CFrame:VectorToObjectSpace(Humanoid.MoveDirection)
while true do
wait(1)
print(Result) --This prints 0,0,0 every 1 second- Doesnt work.
end

Anything that helps me reach my goal would be appreciated, thanks.

0
You might want to use lookvector or something. Might want to look up a tutorial, I'll be back soon with an update. diorlandripp 4 — 4y
0
Okay, you actually might want to use UIS(UserInputService) search up a tutorial about UIS. This might help you. diorlandripp 4 — 4y
0
The UserInputService worked, but with some glitches, i guess i can fix that with no problems,thanks! kevinsoaresv 47 — 4y

1 answer

Log in to vote
0
Answered by
Necro_las 412 Moderation Voter
4 years ago
Edited 4 years ago

I would change the defaut walk animation everytime you press S (or your custom key).

local UIS = game:GetService("UserInputService")
local animateScript = character:WaitForChild("Animate")

-- Change the defaut walk animation:
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationForwards"

-- Walk Backwards animation when pressing S:
UIS.InputBegan:Connect(function(key) 
    if key.KeyCode == Enum.KeyCode.S then
        animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationBackWards"
        end
    end
end)

-- Reset Forward animation when release S:
UIS.InputEnded:Connect(function(key) 
    if key.KeyCode == Enum.KeyCode.S then
        animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationForWards"
        end
    end
end)
  • all defaut animations listed in: https://developer.roblox.com/en-us/articles/using-animations-in-games
0
Maybe this code makes it have to load the assetId every time so it gets laggy, but you can do something in this way anyways, like just changing places with another animation object, so it keeps preloaded. Necro_las 412 — 4y
Ad

Answer this question