I’m trying to make a dash system based on the character’s moving direction, using VectorForce. Everything works fine at a certain point, but sometimes, usually when I jump, I get a extreme high velocity out of nowhere. I tried to use StateChanged to fix that but I’m still getting this weird result. If you realise that I did something wrong with this implementation, please let me know!
Here’s the code:
-- // Services
local UserInputService = game:GetService("UserInputService")
-- // Localization
local character = script.Parent
local root = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
-- // Constants
local DASH_NORMAL = 900 * root.AssemblyMass
local DASH_COOLDOWN = 2
-- // Booleans
local canDash = true
-- // Functions
function dash(root, humanoid)
local mD = humanoid.MoveDirection
local attachment = Instance.new("Attachment")
attachment.Parent = root
local vectorForce = Instance.new("VectorForce")
vectorForce.Parent = root
vectorForce.Attachment0 = attachment
vectorForce.ApplyAtCenterOfMass = true
humanoid.JumpPower = 0
humanoid.WalkSpeed = 0
vectorForce.Force = root.CFrame:VectorToObjectSpace(mD) * DASH_NORMAL
coroutine.wrap(function()
wait(.7)
vectorForce:Destroy()
attachment:Destroy()
humanoid.JumpPower = 50
humanoid.WalkSpeed = 16
end
end)()
end