Dashing through LinearVelocity makes the character go into wrong position

Hey, I’ve been trying to make a movement system but i have a little problem.
Sometimes it goes into the right position, and sometimes it doesn’t.

Here’s an example: https://youtu.be/k4lQppS3Ets

CODE:

local module = {}

local Debris = game:GetService("Debris")

local frDash = Instance.new("Animation")
frDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
local rDash = Instance.new("Animation")
rDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
local lDash = Instance.new("Animation")
lDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"
local bDash = Instance.new("Animation")
bDash.AnimationId = "http://www.roblox.com/asset/?id=xxx"

function module.Dash(player, dashType)
	local anim
	
	local character = player.Character
	local humanoid = character.Humanoid
	
	local att0 = Instance.new("Attachment", character.HumanoidRootPart)
	att0.Parent = character.HumanoidRootPart
	local linearVelocity = Instance.new("LinearVelocity", character.HumanoidRootPart)
	linearVelocity.Attachment0 = att0
	linearVelocity.MaxForce = 100000
	linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

	local dashDuration = 0.33
	local dashSpeed = 100
	
	if dashType == "A" then
		print(dashType)
		anim = humanoid.Animator:LoadAnimation(lDash)
		anim.Priority = Enum.AnimationPriority.Action
		anim:Play()
		linearVelocity.VectorVelocity = -(character.HumanoidRootPart.CFrame.RightVector) * dashSpeed
	elseif dashType == "D" then
		anim = humanoid.Animator:LoadAnimation(rDash)
		anim.Priority = Enum.AnimationPriority.Action
		anim:Play()
		linearVelocity.VectorVelocity = character.HumanoidRootPart.CFrame.RightVector * dashSpeed
	elseif dashType == "W" then
		anim = humanoid.Animator:LoadAnimation(frDash)
		anim.Priority = Enum.AnimationPriority.Action
		anim:Play()
		linearVelocity.VectorVelocity = character.HumanoidRootPart.CFrame.LookVector * dashSpeed
	elseif dashType == "S" then
		anim = humanoid.Animator:LoadAnimation(bDash)
		anim.Priority = Enum.AnimationPriority.Action
		anim:Play()
		linearVelocity.VectorVelocity = -(character.HumanoidRootPart.CFrame.LookVector) * dashSpeed
	end
	Debris:AddItem(att0, dashDuration)
	Debris:AddItem(linearVelocity, dashDuration)
end

return module

1 Like

Setting the LinearVelocity RelativeTo Enum.ActuatorRelativeTo.World may be helpful. The HumanoidRootPart’s LookVector moving around during the animation may be what’s causing unpredictable behavior.

3 Likes

It moves in one pattern, just look close. And hey, setting the relative to world actually helped! I just don’t know why :stuck_out_tongue: Could you explain?

1 Like

And there is now an issue where the character is shaking when dashing, can you tell me how to fix it? I think it’s because the walking animation is trying to overwrite my animation and that’s why it’s happening, but the animation priority is set to action…

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.