Hello, I’m attempting to make a dash system where when a player presses Q, they dash forward.
My problem is I cannot find a good way to go about this. Body Velocity and all that have been depricated, but even if I just go ahead and use it anyway or use ApplyImpulse() I get this problem where if the player jumps, they move faster.
Is there a better way to go about trying to make a dash system, or does anyone know how to overcome this issue I’m facing?
function dash(direction,humanoidRootPart)
print(humanoidRootPart.Parent.Name)
--local velocityTime = 0.25
if hitHumanoidRootPart then
hitHumanoidRootPart:ApplyImpulse(velocityDirection)
end
--velocityModule.knockback(humanoidRootPart, hitHumanoidRootPart)
end
you can set up the values, if you want for player not able to jump while dashing you can just simply remove player’s jumping power
--//Services
local User_Input_Service = game:GetService("UserInputService")
local Player_Service = game:GetService("Players")
--//Player
local Player = Player_Service.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
--//Attributes
local CD_Active = false
--| Main Script |--
local Dash = function(Key)
if Key.KeyCode == Enum.KeyCode.Q and CD_Active == false and Character.Humanoid.FloorMaterial == Enum.Material.Air and Character.Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
Root.AssemblyLinearVelocity += Vector3.new(Character.Humanoid.MoveDirection.X * 100, 0, Character.Humanoid.MoveDirection.Z * 100)
CD_Active = true
task.wait(2)
CD_Active = false
end
end
local isDashing = false
function dash(direction, humanoidRootPart)
if isDashing then
return
end
isDashing = true
local player = game.Players:GetPlayerFromCharacter(humanoidRootPart.Parent)
if not player then
return
end
local character = player.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then
return
end
local velocity = direction * 100 -- Adjust the speed as needed
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = velocity
bodyVelocity.MaxForce = Vector3.new(0, math.huge, 0) -- Adjust max force as needed
bodyVelocity.P = 5000 -- Adjust P value as needed
bodyVelocity.Parent = humanoidRootPart
wait(0.1) -- Adjust this wait time based on your game's needs
bodyVelocity:Destroy()
isDashing = false
end
local player = game.Players.LocalPlayer
local inputService = game:GetService("UserInputService")
inputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
local character = player.Character
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
dash(Vector3.new(0, 0, 1), humanoidRootPart) -- Dash forward
end
end
end)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if isDashing then
humanoid:Move(Vector3.new(0,0,0))
end
end)
end)
The isDashing variable is used to track whether the player is currently dashing. The Jump property of the Humanoid is then monitored, and if the player attempts to jump while dashing, the jump is canceled by setting the character’s velocity to zero.
The issue you’re experiencing where the character travels farther if they dash while jumping is because of friction. While a character is grounded there’s friction that’s slowing down the character’s speed and travel distance but when jumping there isn’t a friction force in Roblox unless you add an air drag force to slow the character down. This would take a lot of time to implement but for now I made this script that might work ok enough. It doesn’t add air drag but it forces the character down when the dash activates to reduce the difference between when the character is jumping or not
-- LocalScript inside StarterCharacterScripts
local ppart: BasePart = script.Parent.PrimaryPart or script.Parent:WaitForChild"HumanoidRootPart"
game.ContextActionService:BindAction("TEST", function(_, is)
if is ~= Enum.UserInputState.Begin then return end
ppart:ApplyImpulse(-ppart.CFrame.UpVector * 1024)
ppart:ApplyImpulse(ppart.CFrame.LookVector * 1024)
end, false, Enum.KeyCode.Q)