Character rotating slightly to the left and no idea why

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)

Hello!

Is it possible the issue lies in the lookvector not being exactly a line forward?

Could you try using line velocity? I hope this solves your issue!

Kevin

Hello, what do you mean by “try using line velocity” ? I’m trying to find what you’re talking about online but can’t, thanks for trying to help me !

I found the solution to my problem !

Basically the attachment that I used for the linear velocity wasn’t at the center of mass of the character.

Glad you have solved your issue!

A linear velocity has a property VelocityConstraintMode on which you can choose the Velocity Constraint Mode to Vector (the one you were using), Plane and Line. Once you set the velocity to line, you can set the line direction and line velocity.

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