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 5 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:

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

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 — 5y
0
Okay, you actually might want to use UIS(UserInputService) search up a tutorial about UIS. This might help you. diorlandripp 4 — 5y
0
The UserInputService worked, but with some glitches, i guess i can fix that with no problems,thanks! kevinsoaresv 47 — 5y

1 answer

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

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

01local UIS = game:GetService("UserInputService")
02local animateScript = character:WaitForChild("Animate")
03 
04-- Change the defaut walk animation:
05animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationForwards"
06 
07-- Walk Backwards animation when pressing S:
08UIS.InputBegan:Connect(function(key)
09    if key.KeyCode == Enum.KeyCode.S then
10        animateScript.walk.WalkAnim.AnimationId = "rbxassetid://CustomAnimationBackWards"
11        end
12    end
13end)
14 
15-- Reset Forward animation when release S:
View all 21 lines...
  • 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 — 5y
Ad

Answer this question