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

Make a localscript on startercharacterscripts and a remote event parented to it, and a normal script parented to the remote event.

copy this to the local script:


--[ LOCAL SCRIPT ] --

local plrs = game:GetService("Players")
local pl = plrs.LocalPlayer
local ch = pl.Character or pl.CharacterAdded:Wait()
local hm = ch:WaitForChild("Humanoid")
local remote = script.RemoteEvent

remote:FireServer(hm)

hm.StateChanged:Connect(function()

hm:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
hm:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)

end)

And this on the server script:


-- [ SERVER SCRIPT ] --

local remote = script.Parent

remote.OnServerEvent:Connect(function(pl, hm)

    hm.StateChanged:Connect(function()

       hm:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
       hm:SetStateEnabled(Enum.HumanoidStateType.FallingDown,false)

    end)
end)

Tell me if there is any errors