Mouse.Hit Range

I want to make a part follow the player but only within 30 studs. The problem is that it is snappy.
https://gyazo.com/d3c0532321c78e307e39f87637156d2c

this is the code I’m using

game:GetService("RunService").RenderStepped:Connect(function()
	if mouse.Hit then
		RootPos = c.HumanoidRootPart.Position
		if (RootPos - mouse.Hit.Position).Magnitude < 30 then
			workspace.MeshPart.Position = Vector3.new(mouse.Hit.p.X,0,mouse.Hit.p.Z)
		end
	end
end)

Try clamping the meshpart’s position to a radius of 30 instead instead of checking the mouse.hit magnitude.

You can achieve this by calculating the difference between your position and the mouse’s, then clamping each axis between -30 and 30

You can of course go more advanced but hopefully this puts you on the right track.

i tried the clamp thing before and i was wondering why it only went to the right. Its because i forgot about the negitives :man_facepalming:

1 Like

Haha it’s alright, it happens! Happy developing!