How do I make a dash ability?

Now before you link me to some post please note I dont want to use physics, well unless there is a way to do this with physics.

Basically I want a dash ability but I dont want to use some kinda physics cause if you dash into a wall you start bouncing around and your body acts weird and what not, So how can I achieve this?

1 Like

I use a method that uses runservice and it avoids the usually bouncing into walls and weirdness with jumping. I did not write the script and cannot explain it though.

local _DashDistance = 20
local _DashDuration = 0.4
local _DashSpeed = _DashDistance / _DashDuration
local LastDash = 0
local LastMDirection = Vector3.new()

function EaseQuarticIn(a, b, t, d)
	local c = b - a
	t /= d
	return c * t * t * t * t + a
end

function Lerp(a, b, t) 
	return a + (b - a) * t
end

function OnRenderStepped()
	local DashSpeed = EaseQuarticIn(_DashSpeed, 0, math.min(tick() - LastDash, _DashDuration), _DashDuration) 

	local DashVelocity = LastMDirection * DashSpeed

	local Velocity = Root.AssemblyLinearVelocity

	Root.AssemblyLinearVelocity = DashSpeed > 0 and Vector3.new(DashVelocity.X, Velocity.Y, DashVelocity.Z) or Velocity
end

local function Dash(actionName, inputState)
	if inputState == Enum.UserInputState.Begin then
		if Humanoid.MoveDirection.Magnitude > 0 then -- Won't dash if standing still
			local t = tick()

			LastDash = t
			LastMDirection = Humanoid.MoveDirection
		end
	end
end
1 Like

c * t * t * t * t * t + a looks like nightmare fuel :sob:

4 Likes

@Earthraphobic2 I agree. That code won’t even work.

@FroDev1002 If you want something like a simple shift to sprint script, try this! Beginner Tutorial #3: How To Make A Simple Shift To Sprint Script! - Resources / Community Tutorials - Developer Forum | Roblox

Hope it helps! :slight_smile:

Oh well I mean more of like in a lot of battling games theres an ability that launches you forwards, or you “dash” thanks though

1 Like

Are you wanting to know how to make one?

Yes indeed! No point of just getting one for free, learning is good!

1 Like

Exactly! I think the best way to do it would be in your attack script or module, create a value and/or variable to detect when the player triggers the attack. Create a Dash function and check if the value is true (it will be true while the attack is running and when it stops, set it to false) then call the function and if it’s not, do nothing. I’ve done something similar to this, but not exact, so I don’t know how well it will work, but I hope it helps you!

1 Like

Well I understand the functions and stuff, and making it so the function would be called but how do I make the user actually “dash”

1 Like

Is your script server or local? That depends on how it will be made.

I havent made it yet cause I wasnt sure how to go about it

1 Like

Your dash script could look something like this:

--Local Script
local Character = script.Parent
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")

local CanSlide = true

local function Dash()
	if not CanSlide then return end
	CanSlide = false

	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(1, 0, 1) * 30000
	BodyVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * 100
	BodyVelocity.Parent = HumanoidRootPart

	for count = 1, 8 do
		task.wait(0.1)
		BodyVelocity.Velocity *= 0.7
	end
	BodyVelocity:Destroy()
	CanSlide = true
end

--Just for testing as if attacking
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(Dash)

So uh will this solve this problem?

So if I was to dash into a wall this wouldnt happen?

1 Like

My avatar just hits the wall and nothing will happen unless you move the character.

1 Like

Welp it works! Other than there being some sliding it works pretty well! Thanks!

1 Like

You’re welcome! Glad I could help you! :slight_smile:

1 Like

My dodge script will and does work. And unlike your solution mine does not lock the player’s movement for the duration of the dash nor does it slow down near the end of it.

1 Like

Your script doesn’t work for me. I know that when using mine there is a little bit of sliding but it does not lock the player’s movement.

That’s cause I didn’t include the BindAction in my script :sob:

1 Like

Oh, that makes sense. I bet it would work with that action set up.