Linear Velocity not working as intended

Having a problem with my wall climbing movement velocity. Supposed to be moving them across the axis of the wall, but instead they just move randomly. Movement isn’t capped to the wall yet, either.

Here’s my code:

local RepStorage = game:GetService("ReplicatedStorage")
local Remotes = RepStorage.Remotes

local WallClimbingRemote = Remotes.WallClimbingInput

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char.Humanoid
	local hrp = char.HumanoidRootPart
	
	local playerIsClimbing = false
	
	WallClimbingRemote.OnServerEvent:Connect(function(player, direction)
		if player == plr then
			if playerIsClimbing == true then
				local velocity = hrp:FindFirstChild("LinearVelocity")
				
				if velocity then
					print('velocity found')
					if direction == "Right" then
						velocity.VectorVelocity = Vector3.new(90,0,0)
					elseif direction == "Left" then
						velocity.VectorVelocity = Vector3.new(-90,0,0)
					end
					velocity.MaxForce = 15000
				end
			end
		end
	end)
	
	while wait() do
		local wall = workspace.Wall
		if not wall then continue end
		if not hrp then continue end
		if playerIsClimbing then continue end
		
		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Exclude
		raycastParams.FilterDescendantsInstances = {char}
		
		local direction = hrp.CFrame.LookVector*1.5
		local raycastResult = workspace:Raycast(hrp.Position, direction, raycastParams)
		
		if not raycastResult then continue end
		
		if raycastResult.Instance then
			if raycastResult.Instance == wall then				
				if not playerIsClimbing then
					
					hrp.CFrame = CFrame.lookAt(raycastResult.Position, raycastResult.Position + Vector3.new(0,0,-0.15))	
					hum.PlatformStand = true
					
					local alignPosition = Instance.new('AlignPosition')
					alignPosition.Mode = "OneAttachment"
					alignPosition.Parent = hrp
					
					local attachment0 = Instance.new("Attachment")
					attachment0.Name = "Attachment0"
					attachment0.Parent = hrp
					
					alignPosition.Position = raycastResult.Position
					alignPosition.Attachment0 = attachment0
					
					hrp.Orientation = Vector3.new(0,0,0)
					hum.AutoRotate = false
					
					local linearVelocity = Instance.new("LinearVelocity")
					linearVelocity.MaxForce = 0
					linearVelocity.Parent = hrp
					
					local attachment0 = Instance.new('Attachment')
					attachment0.Name = "VelocityObject"
					attachment0.Parent = hrp
					
					linearVelocity.Attachment0 = attachment0
					
					playerIsClimbing = true
				end
			end
		end
	end
end)

– Bump

–Minimum characters–

–Bump again-- Minimum characters

—Bump x3 —

Minimum characters

Linear velocities are a little different than they may seem. They essentially add a concrete velocity to a part that doesn’t decelerate. So when a linear velocity changes direction, instead of setting the part’s velocity instantly to the new velocity it adds the new velocity unto the old one. To truly extract a refined linear velocity function of what I think you are trying to achieve try this:


if velocity then
	print('velocity found')
	hrp.AssemblyLinearVelocity = Vector3.new(0,0,0)
	if direction == "Right" then
		velocity.VectorVelocity = Vector3.new(90,0,0)
	elseif direction == "Left" then
		velocity.VectorVelocity = Vector3.new(-90,0,0)
	end
	velocity.MaxForce = 15000
end

I could be mistaken on the issue though, if this doesn’t work try making sure your linear velocity RelativeTo setting is set to World

I wouldn’t use this deprecated Instance, as some unintended things may happen whilst using it.


I would instead use the BasePart.AssemblyLinearVelocity property, to set the actual velocity of a part. Try that instead.