How to make the player dash in their moving direction

I’m trying to make a dash system. You can dash in your moving direction and every direction has its own animation.

Here is the script I have right now:

local Keybind = Enum.KeyCode.Q

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

local UIS = game:GetService("UserInputService")

local DashTime = .2
local Force = 70

local Anims = {
	["Left"] = Animator:LoadAnimation(script.Animations:WaitForChild("Left")),
	["Right"] = Animator:LoadAnimation(script.Animations:WaitForChild("Right")),
	["Foward"] = Animator:LoadAnimation(script.Animations:WaitForChild("Forward")),
	["Back"] = Animator:LoadAnimation(script.Animations:WaitForChild("Back"))
}

UIS.InputBegan:Connect(function(Key)
	if Key.KeyCode == Keybind then

		local Slide = Instance.new("BodyVelocity")
		Slide.MaxForce = Vector3.new(1,0,1) * 30000
		Slide.Velocity = Humanoid.MoveDirection * Force
		Slide.Parent = Character.HumanoidRootPart

		wait(DashTime)

		game.Debris:AddItem(Slide, 0.1)
			
		for count = 1, 2 do
			wait(0.05)
			Slide.Velocity *= 0.3
		end

	end
end)

I found out how to create the dash, however i dont know how i would implement the animations.

1 Like

You could detect if player is pressing WASD keys by using bool values (true/false) and bind detection. To do this, you may need to create InputBegan functions and connect them to WASD keys, if some of these keys are being pressed then you can set their bool values to true or if they being released set them to false. In the main function you can check if WASD’s bool values are true and you can play an animation if they’re true.
I may explained it bad but i cant do anything with it.

1 Like