Im currently working on a dash system, except Im having some issues.
First off, the most annoying one. Flinging.
Since Im using a linear velocity, if you dash and hit the floor your character usually starts freaking out lol.
The other issue is that I would like it so if your body turns, the force of your dash continues in that direction.
I have no idea how to solve either issue, so I was hoping someone here might be able to help!
Action Handler Section
local function OnActionTriggered(Action:string, State:Enum.UserInputState)
local Begin = State == Enum.UserInputState.Begin
Actions[Action] = Begin
-- // Main //
if Action == 'Dash' and Begin then
local MoveDirection:Vector2 = MovementHumanoid.MoveDirection
-- // Values
local RootCFrame = Character.PrimaryPart.CFrame
local Force = 0
local DirectionString = nil
local DirectionVector = nil
if MoveDirection.Y == 1 then
DirectionString = 'Forwards'
DirectionVector = RootCFrame.LookVector
elseif MoveDirection.Y == -1 then
DirectionString = 'Backwards'
DirectionVector = -RootCFrame.LookVector
elseif MoveDirection.X == 1 then
DirectionString = 'Right'
DirectionVector = RootCFrame.RightVector
else
DirectionString = 'Left'
DirectionVector = -RootCFrame.RightVector
end
print(DirectionString, MoveDirection)
-- // Cooldown
if DirectionString == 'Forwards' or DirectionString == 'Backwards' then
if Cooldowns.FrontDash then return end
Cooldowns.FrontDash = true
Force = -100
else
if Cooldowns.SideDash then return end
Cooldowns.SideDash = true
Force = 50
end
-- // Dash //
local Velocity = Instance.new('LinearVelocity')
local Length = 2
Velocity.Attachment0 = Character.PrimaryPart:FindFirstChild('RootAttachment')
Velocity.MaxForce = math.huge
Velocity.VectorVelocity = DirectionVector * Force
Velocity.RelativeTo = Enum.ActuatorRelativeTo.World
Velocity.Parent = Character.PrimaryPart
-- // Queue
local Item = {
Start = tick(),
End = tick() + Length,
DirectionString = DirectionString,
Velocity = Velocity,
Force = Force
}
table.insert(Queues, Item)
-- // Finish Cooldown
task.wait(Length)
Velocity:Destroy()
if DirectionString == 'Forwards' or DirectionString == 'Backwards' then
task.wait(0)
Cooldowns.FrontDash = false
else
task.wait(0)
Cooldowns.SideDash = false
end
end
end
Renderstep to update the Velocity, which seems to not work
RunService.RenderStepped:Connect(function(DeltaTime)
-- // Queues //
for Index, Queue: {Start:number?, End:number?, Action:string} in Queues do
-- // Remove Queue
if Queue.End then
if tick() >= Queue.End then
table.remove(Queues, Index)
end
end
-- // Run //
if Queue.Action == 'Dash' then
local Velocity:LinearVelocity = Queue.Velocity
local Direction = Queue.DirectionString
local RootCFrame = Character.PrimaryPart.CFrame
assert(Velocity, 'No Velocity Found')
if Direction == 'Forwards' then
Velocity.VectorVelocity = (RootCFrame.LookVector * Queue.Force) * 0.8
elseif Direction == 'Backwards' then
Velocity.VectorVelocity = (-RootCFrame.LookVector * Queue.Force) * 0.8
elseif Direction == 'Right' then
Velocity.VectorVelocity = (RootCFrame.RightVector * Queue.Force) * 0.8
elseif Direction == 'Left' then
Velocity.VectorVelocity = (-RootCFrame.RightVector * Queue.Force) * 0.8
end
end
end
end)
PS
Queues
is just a table, nothing special
Thanks in advanced!