I’m trying to create a dash system for an r6 combat game, like in the game ‘The Strongest Battlegrounds’.
I’m not really an expert when it comes to roblox physics and velocitys, so I don’t really have any idea of how to do it. Though, I have looked around on the developer forum for some sort of guidance, but most of the solutions are using BodyVelocity, which is deprecated.
The following script will make the player dash whenever they press Q on the keyboard or L1 on their controller
--- input template
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid") :: Humanoid
local Camera = workspace.CurrentCamera
local BV = script.BodyVelocity
local Settings = {
Lifetime = 0.12;
DashVelocity = 100;
Cooldown = 1;
}
local Keycodes = {
[Enum.KeyCode.Q] = true;
[Enum.KeyCode.ButtonL1] = true;
}
local function f()
local Now = workspace:GetServerTimeNow()
local DashCooldown = Character:GetAttribute("DashCooldown") or 0
if DashCooldown > Now then return end
Character:SetAttribute("DashCooldown", Now + Settings.Cooldown)
local NewBV = BV:Clone()
local Direction = Humanoid.MoveDirection
if Direction.Magnitude == 0 then
Direction = RootPart.CFrame.LookVector
end
local CamP0 = Camera.CFrame.LookVector
local RelativeDirection = CFrame.lookAt(CamP0, CamP0 + Direction).LookVector
NewBV.Velocity = RelativeDirection * Settings.DashVelocity
NewBV.Parent = RootPart
task.delay(0.12, function()
NewBV:Destroy()
end)
end
UIS.InputBegan:Connect(function(InputObject: InputObject, SunkInput: boolean)
if SunkInput then return end
if not Keycodes[InputObject.KeyCode] then return end
f()
end)