I need help with making a directional dashing animation, like… Uhm… changing the forward dash to a right side dash when the character is moving right. I also planned on making the animation only change when the player is shiftlocking, basically they’ll always dash forward.
I’ve seen some topics in the forum about this but most of them are uhh what’s the word??? Uses keyboard enums (W, A, S, D) stuff.
I wanna try making it work for mobile + console, using the MoveDirection property from Humanoid in some way.
Here’s my initial code.
...
--# anim
local dash = humanoid:LoadAnimation(anims.Dash)
--# get direction
local dir
if humanoid.MoveDirection.Magnitude > 0 then
local movement = humanoid.MoveDirection
-- tried doing some vector calculation and make it
-- make it change the animation here earlier but
-- what i do just doesn't really work correctly
dir = humanoid.MoveDirection * 75
else
dir = root.CFrame.LookVector * 75
end
dash:Play(0.05)
task.delay(0.5, function()
dash:AdjustSpeed(0)
end)
...
Tried finding a way to make it work, but now I need your guys help for this one cuz I’m kinda lost
Went to eat really quick but I got it done. You’d have to implement the move direction stuff on your own because now it just dashes to random directions randomly
Here’s some quick dash code:
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Root = Humanoid.RootPart
local Multiplier = 100
local Time = .25
local IsDashing = false
local function ProcessInput(InputObject:InputObject, GameProcessed:boolean)
if IsDashing or GameProcessed or InputObject.KeyCode ~= Enum.KeyCode["Q"] then return end
IsDashing = true
local Linearvel = Instance.new("LinearVelocity")
Linearvel.Attachment0 = Root:FindFirstChild("RootAttachment")
Linearvel.MaxForce = math.huge
local ChosenDir:Vector3;
local RandomDir = math.random(1,4)
if RandomDir == 1 then
ChosenDir = Root.CFrame.LookVector
print("Front")
elseif RandomDir == 2 then
ChosenDir = -Root.CFrame.LookVector
print("Back")
elseif RandomDir == 3 then
ChosenDir = Root.CFrame.RightVector
print("Right")
elseif RandomDir == 4 then
ChosenDir = -Root.CFrame.RightVector
print("Left")
end
Linearvel.VectorVelocity = ChosenDir * Multiplier
Linearvel.Parent = Humanoid.RootPart
task.delay(Time,function()
IsDashing = false
Linearvel:Destroy()
end)
end
UIS.InputBegan:Connect(ProcessInput)
local function rotateVectorAround( v, amount, axis )
return CFrame.fromAxisAngle(axis, amount):VectorToWorldSpace(v)
end
local shiftLock = UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter
local velocity = humanoid.MoveDirection
velocity -= Vector3.new(0, velocity.Y, 0)
local anim
if velocity.Magnitude > 0 then
local movingForward, movingBackward, movingRight, movingLeft
local _, y, _ = camera.CFrame:ToEulerAnglesYXZ()
local movementDirection = rotateVectorAround(velocity, -y, Vector3.yAxis)
-- Add 0.01 to Z to prioritize front roll if diagonal
if math.abs(movementDirection.X) >= math.abs(movementDirection.Z) + 0.01 then
movingRight = movementDirection.X >= 0
movingLeft = movementDirection.X < 0
else
movingBackward = movementDirection.Z >= 0
movingForward = movementDirection.Z < 0
end
if movingForward or not shiftLock then
anim = -- front roll
elseif movingBackward then
anim = -- back roll
elseif movingRight then
anim = -- right roll
elseif movingLeft then
anim = -- left roll
end
else
anim = -- front roll
end