Linear Velocity bugging out

I’m trying to make a system where I get pulled to a part. Now I know people would recommend using tweenservice or lerping but I need this to be very responsive, smooth, and have a way for me to be able to orbit around the point by choice. However for some reason My character will just start spiraling out of control. Here’s My localscript.

local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera


local function CreateRayCast()
	local mousePosition = uis:GetMouseLocation()
	local rayCast = camera:ViewportPointToRay(mousePosition.X,mousePosition.Y)
	local params = RaycastParams.new()
	local RaycastResult = workspace:Raycast(rayCast.Origin,rayCast.Direction * 20000,params)
	return RaycastResult
end


uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		print("input began")
		local hook = player.Character.ODM.LeftHook
		local raycastResult = CreateRayCast()
		if raycastResult and raycastResult.Instance then
			print("raycasted!")
			local tbl = {
				instance = raycastResult.Instance,
				position = raycastResult.Position,
			}
			RS.Move:FireServer(tbl, hook)
		else
			print("no raycast :(")
		end
	end
	if input.KeyCode == Enum.KeyCode.E then
		print("input began")
		local hook = player.Character.ODM.RightHook
		local raycastResult = CreateRayCast()
		if raycastResult and raycastResult.Instance then
			local tbl = {
				instance = raycastResult.Instance,
				position = raycastResult.Position,
			}
			RS.Move:FireServer(tbl, hook)
		end
	end
end)

Here’s My serverscript

local RS = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local velocity
RS.Move.OnServerEvent:Connect(function(player, tbl, hook)
	local target, TargetPos = tbl["instance"],tbl["position"]
	print(target)
	print(TargetPos)
	local HitAttachment = Instance.new("Attachment", target)
	HitAttachment.Name = "HitAttachment"
	HitAttachment.WorldPosition = TargetPos
	local LinearV = Instance.new("LinearVelocity", hook)
	RunService.Stepped:Connect(function()
		velocity = CFrame.new(player.Character.HumanoidRootPart.Position,HitAttachment.WorldPosition).LookVector * 100
		LinearV.VectorVelocity = velocity
		print(velocity)
	end)
	LinearV.MaxForce = math.huge
	player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll, false)
	player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown, false)
	LinearV.Attachment0 = player.Character.HumanoidRootPart.RootAttachment
	print(velocity)
end)

And here’s a video of my problem. It shows what happens If I hit a part on my way to the target.

https://streamable.com/ssbkiw

1 Like