Hello ! I’m having an issue where for some reason, after applying the linear velocity to my character’s HumanoidRootPart it slightly rotate to the left, meaning that with this code my character does an arc of a cirlce and isn’t going straight when dashing. I tried messing with the values, I tried deactivating and reactivating things in my other scripts so I’m pretty sure this one is the culprit, I’ve also tried replacing the linear velocity by body velocity and it did work, but I want to use linear velocity as body velocity is deprecated.
Anyways, here is the most probable culprit below.
local RS = game:GetService("ReplicatedStorage")
local Skill = script.Parent
local char = game.Players.LocalPlayer.Character
local SkillEvent = RS.Events.Skill
Skill.Equipped:Connect(function()
SkillEvent:FireServer("Leaping Slash")
Skill.Parent.Humanoid:UnequipTools()
end)
SkillEvent.OnClientEvent:Connect(function(arg)
if arg == "Dash" then
local dashDuration = 0.35
local rate = 0.05
local velocity = 100
local direction = char.HumanoidRootPart.CFrame.LookVector
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.MaxForce = 100000
linearVelocity.Attachment0 = char.HumanoidRootPart.RootAttachment
linearVelocity.Parent = char.HumanoidRootPart
local minimumVelocity = 0
local ammountOfIteration = dashDuration/rate
local removalOfVelocityPerIteration = velocity/ammountOfIteration
for i = 0, dashDuration, rate do
local direction = char.HumanoidRootPart.CFrame.LookVector
linearVelocity.VectorVelocity = direction*velocity
if velocity>minimumVelocity then
velocity-=removalOfVelocityPerIteration
if velocity<minimumVelocity then
velocity = minimumVelocity
end
end
wait(rate)
end
linearVelocity:Destroy()
end
end)