Linear Velocity Direction Issue?

I’m trying to make a system where I can click and as long as I haven’t released my click I’m drawn towards the part (kind of like ODM gear from Attack On Titan if you’re familiar)

Well, I feel as though my REAL issue is that I’m new to working with physics constraints and I have a lackluster knowledge of CFrame/Vector math.

Here’s the problem I’m posting about… For some reason, Linear Velocity seems to almost have a “drag” when its correcting for where I’m trying to face the attachment.

It’s hard to explain and I may not be understanding my issue correctly,
so here’s a video demonstrating it:

https://i.gyazo.com/833c3b551b5f61ec2c75a571381851c8.mp4

It may be hard to notice in the video but the blue arrow, if I’m not mistaken, is where the linear velocity is moving me towards, and then the red, forcefield, part is where I’m trying to end up (where I’ve clicked)

Here’s my code:

	if gpe then return end
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			local mouseHitPos = mouse.Hit.Position
		
		if (mouseHitPos - char.HumanoidRootPart.Position).Magnitude > maxStuds then
			warn("TOO FAR")
		elseif debounce == true then
			warn("DEBOUNCE")
		else
			debounce = true
			lineCast = true
			
			local clickPart = Instance.new("Part")
			clickPart.Anchored = true
			clickPart.Name = "clickPart"
			clickPart.Material = Enum.Material.ForceField
			clickPart.Color = Color3.fromRGB(255, 0, 4)
			clickPart.Position = mouseHitPos
			clickPart.Size = Vector3.new(1.25,1.25,1.25)
			clickPart.CanCollide = false
			clickPart.CanQuery = false
			clickPart.Parent = workspace
			
			local hookAtt = Instance.new("Attachment")
			hookAtt.Name = "hookAtt"
			hookAtt.Parent = clickPart
			
			if lineCast then
				local hrpAtt = Instance.new("Attachment")
				hrpAtt.Name = "hrpAtt"
				hrpAtt.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
				hrpAtt.WorldPosition = char.HumanoidRootPart.Position
				char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
				hrpAtt.Parent = char.HumanoidRootPart
				
				local lv = Instance.new("LinearVelocity")
				lv.Visible = true
				lv.Name = "lv"
				lv.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
				lv.MaxForce = 40000
				lv.Attachment1 = hrpAtt
				lv.VectorVelocity = Vector3.new(100,0,0)
				lv.Attachment0 = hrpAtt
				lv.Parent = char.HumanoidRootPart
				
				
				while lineCast do
					task.wait()
					hrpAtt.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
					hrpAtt.WorldPosition = char.HumanoidRootPart.Position
					char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
				end
				
				
				delay(cpDebrisTimer, function()
					if lineCast == true and hookAtt and clickPart and hrpAtt and lv then
						hookAtt:Destroy()
						clickPart:Destroy()
						hrpAtt:Destroy()
						lv:Destroy()
					--	print("deleting", hookAtt, clickPart, hrpAtt, lv)
					end
				end)
				
				delay(debTimer, function()
					debounce = false
				end)
			end
		end
	end
end)

I’ve tried a few different things and they don’t seem to be working, I also find tutorials online to not be very helpful for my situation as they usually aren’t for moving a player towards an object (ODM gear style)

Help/Feedback is appreciated, thank you!

5 Likes

Your problem is that you are not moving in a straight line to the target?

1 Like

well kinda, I dont need it arrow straight but Id like it to not try to orbit the target lol.

What the reason for the 100 in here? Could you try it without to see if it still drifts to one side?

Mixxing the vector velocity that works with physics might not be the best way to be doing it if you want the player to stay facing the part. I would:

A. Use a align orientation along with the linear instead of this:
while lineCast do
task.wait()
hrpAtt.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
hrpAtt.WorldPosition = char.HumanoidRootPart.Position
char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, hookAtt.WorldPosition)
end

or

B. Do something like this
–This faces the player toward then position
char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, targetPosition)
char.HumanoidRootPart.CFrame += char.HumanoidRootPart.CFrame.LookVector * speed

1 Like

Why don’t you use an AlignPosition?

1 Like

Idk what that is :expressionless:, got a api link for me?

Someone else mentioned Align Position, I have never heard of either, you got an api link?

EDIT: Position*

Would AlignPosition be better than just setting the position, why would this be?

Have you tried something like this yet?
char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, targetPosition)
char.HumanoidRootPart.CFrame += char.HumanoidRootPart.CFrame.LookVector * speed