How do I make directional dashing animation with MoveDirection?

Hi!

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

1 Like

Are you using linear velocities for this?

No! :fire:
I used BodyVelocity because I feel more familiar with that.

I think BV is deprecated. Am I wrong?

Uh so I’d recommend using linear velocity to begin with because body velocity is outdated and the myth that its smoother is just false.

Also, you’d wanna use the humanoid root part’s lookvector, right, and left vectors

Edit: I was already in studio so I’ll cook up some quick dash code cz its not hard

1 Like

It is deprecated, I know. Just feels… It just still works.
Don’t really care much if its smooth or no.

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

Spoon feed but this is how i went about it

Woo! This one is what I’m looking for, thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.