LinearVelocity Changing Characters Direction

I’m trying to make a Slide System using LinearVelocity since BodyVelocity is deprecated, everything was going well until I ran into a problem. everytime near the end the players character sort of rotate to the right. I’ve tried doing everything to solve this on my own & search for similar issues but still nothing.

The script I made

-- Function
SlideAbility = function()
	
	-- Settings
	Humanoid.WalkSpeed = 0 
	Humanoid.AutoRotate = false
	
	-- Animation
	local SlideTrack = Humanoid:LoadAnimation(SlideAnimation)
	SlideTrack.Priority = Enum.AnimationPriority.Action
	SlideTrack:Play()
	
	-- Attachment Settings
	local Attachment = Instance.new("Attachment") -- Creates an attachment
	Attachment.Parent = RootPart -- Attaches the attachment to the player's root part
	Attachment.WorldPosition = RootPart.AssemblyCenterOfMass
	
	-- LinearVelocity Settings
	local Velocity = Instance.new("LinearVelocity")
	Velocity.MaxForce = 10000 -- The force of the LinearVelocity
	Velocity.Attachment0 = Attachment -- Attaches the LinearVelocity to the player's root part
	Velocity.RelativeTo = Enum.ActuatorRelativeTo.World -- Makes it so the LinearVelocity does not use person getting up as direction starting point
	Velocity.VectorVelocity = RootPart.CFrame.LookVector * SlideInfo.Speed -- The direction and speed of the LinearVelocity
	Velocity.Parent = RootPart -- Attaches the LinearVelocity to the player's root part
	
	for Count = 1,8 do -- This loop will make the player slide for a certain amount of time
		task.wait(.1) -- The amount of time the player will slide for
		Velocity.LineVelocity *= 0.7 -- The speed of the player sliding
	end
	
	

	Velocity:Destroy()
	Attachment:Destroy()
	SlideTrack:Stop()
	Humanoid.WalkSpeed = 0
	Humanoid.AutoRotate = true
end

Don’t mind the quality I’m on a potato laptop

Only fix I could think of is:

Velocity.VectorVelocity = RootPart.CFrame.LookVector * SlideInfo.Speed + Vector3.new(0, 20, 0)

It works!! Thank you! if you don’t mind can you give me a brief explanation on why this works?

In the original code when you slide, the root part is most likely colliding with the ground because of the animation. The fix I posted resolves this issue by setting the vector velocity’s y value to a high number essentially making it so that the root part may not collide with the ground.

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