Basically what i want to do is when the player presses Q, they dash a bit forward, based on where the character is looking.
That’s basically it, if anyone is able to help i would appreciate a lot.
Basically what i want to do is when the player presses Q, they dash a bit forward, based on where the character is looking.
That’s basically it, if anyone is able to help i would appreciate a lot.
For a very basic dash, you could insert a BodyVelocity into the HumanoidRootPart of the character every time Q is pressed, then set the velocity of it to be the lookVector of the HumanoidRootPart * number.
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local debounce = false
uis.InputBegan:Connect(function(key, processed)
if debounce or processed then
return
end
if key.KeyCode == Enum.KeyCode.Q then
debounce = true
humanoid.WalkSpeed += 8
task.wait(0.5)
humanoid.WalkSpeed -= 8
end
task.wait(1.5)
debounce = false
end)
Local script in StarterCharacterScripts folder. Values can be changed to fit your needs.
If you want a dash that they can change directions with you could increase the walkspeed to something high for a split second and then set it back to normal.
Was gonna say this, you should also add the bodyvelocity to debris so you don’t have to pause the script and the dash is basically in an instant.
…like so:
local Bv = Instance.new("BodyVelocity", script.Parent.Torso)
Bv.P = 1250 -- doesn't really matter
Bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) -- doesn't really matter
Bv.Velocity = script.Parent.Torso.CFrame.lookVector*50 -- adjust this until its right
-- putting it to negative will make the player go back if you want that too
game.Debris:AddItem(Bv,0.1) -- adjust 0.1 until its right too
Nah scratch that I’ll make an entire script for you 'cause I’m bored
Dashing Ability! - Roblox (uncopylocked)
How it looks: (everything is configurable!)
Code (use the uncopylocked place’s version, otherwise this will error out btw):
local Debris = game:GetService('Debris')
local UIS = game:GetService('UserInputService')
local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character
-- Settings
local DashTime = 0.2
local Amount = 50
local MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local P = 1250
local Cooldown = false
local CooldownTime = 2
local TrailEnabled = true
local R15 = true
UIS.InputBegan:Connect(function(i, g)
if not g and i.KeyCode == Enum.KeyCode.Q and Cooldown == false then
local Bv = Instance.new("BodyVelocity")
if R15 then
Bv.Parent = Character.UpperTorso
else
Bv.Parent = Character.Torso
end
Bv.P = P
script.Dash:Play()
Bv.MaxForce = MaxForce
if R15 then
Bv.Velocity = Character.UpperTorso.CFrame.lookVector*Amount
else
Bv.Velocity = Character.Torso.CFrame.lookVector*Amount
end
Debris:AddItem(Bv,DashTime)
Cooldown = true
for _, v in pairs(Character:GetChildren()) do
if v:IsA("BasePart") and TrailEnabled then
local Att1 = Instance.new("Attachment", v)
Att1.Orientation = Vector3.new(-90, 0, 0)
Att1.Position = Vector3.new(0,0.5,0)
local Att2 = Instance.new("Attachment", v)
Att2.Orientation = Vector3.new(-90, 0, 0)
Att2.Position = Vector3.new(0,-0.5,0)
local Trail = Instance.new("Trail", v)
Trail.Attachment0 = Att1
Trail.Attachment1 = Att2
Trail.Lifetime = 0.1
Debris:AddItem(Att1, CooldownTime)
Debris:AddItem(Att2, CooldownTime)
Debris:AddItem(Trail, 0.5)
end
end
task.wait(CooldownTime)
Cooldown = false
end
end)
To make this 10x better and have it work with other animations just use the Humanoids Move direction instead of the Torsos lookVector!
Bv.Velocity = Character.Humanoid.MoveDirection*Amount
Yeah, I figured this out shortly after I posted that and forgot to update it
Bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector*Amount
I would recommend this! The character won’t be pushed into the floor + the character will also dash forward, if not currently moving
Using math.huge
for the MaxForce of a BodyVelocity in the case of dashes can make the dashes too aggressive and, once you dash onto a part, you could get easily flung.
What I recommend is:
Vector3.new(100000, 100000, 100000)
.Vector3.new(100000, 0, 100000)
.An aditional information:
Even changing the MaxForce to something lower can make you get flung or “ragdolled” while dashing. I recommend disabling the FallingDown HumanoidStateType if you often fall while dashing onto a part in a LocalScript.
Woah thanks alot for those recommendations!
This is a late reply , but to make an accurate dash ability that doesn’t glitch in the walls, you can use a raycasting. How to do this? Well first you need to shoot a ray from the humanoidRootPart forwards.
Then you need to find the magnitude ( The lenght of the ray). Then you add a bodyVelocity to the player’s root part. This doesn’t fix the glitching into walls problem . to fix it you need to calculate a time value and delete the velocity after that time. How do you do this? Well It’s really simple. You actually learn this in school. Here is the formula :