I’m currently making a fighting game, and I’d like to add a sprinting system that makes you walk faster and changes your walk animation while you’re running forwards. However, there are things that I haven’t figured out so far:
How would I make it detect that you’re running forwards on mobile or console?
On PC, I could simply check if the player is holding the “W” key and go from there, however, on mobile, I have no idea how i could check if the player is going forwards.
How would I make it change the walking animation without it overriding the existing animations (Punching, dashing, etc)
I’ve tried to find solutions for these, but I couldn’t find anything useful. Any help is appreciated.
None of these are what I’m looking for either… I kind of feel like you didn’t really read my post. I also said in the post itself that I already searched for it, but I couldn’t find it.
I did read through your post. And if nothing matched your context then the simplest way to explain it would be:
Make a sprinting animations and set it’s priority to something above your walking animations but ensure it’s less than that of your other animations (Punching, dashing, etc)
Detect key presses using ContextActionService for sprinting which adds a button for mobile automatically.
To check if player goes forward you use some CFrame maths like so:
local moveDirection = Humanoid.MoveDirection
local relativeDireection = HumanoidRootPart.CFrame:VectorToObjectSpace(moveDirection)
local forwardDirection = relativeDirection.Z
If the forward direction is less than zero then the player is moving forwards.
To play the animation just load the animation to the humanoids animator and play it when you sprint and stop it when you… don’t sprint.
the example script seems to have worked, i would just have to find a way to fix it not detecting the player moving forwards if the camera if the player is rotating rapidly with shiftlock and if the player is walking diagonally (A + W or D + W)