How do I make the smaller circle move smoothly along the edge of the bigger circle?

  1. What do you want to achieve?
    I want the smaller circle to move smoothly along the edges of the bigger circle.

  2. What is the issue?
    Currently I made a script that prevents the smaller circle from going beyond the bigger circle. I am unsure of how to make it so that it can moves smoothly along the bigger circle.
    https://gyazo.com/812b8e2350f3c87ae5eb1ad325467751

The script that I’m using currently vvv

local function move()
	if (Mouse.Hit.p - char.HumanoidRootPart.CFrame.p).Magnitude <= 100 then
		newTS.CFrame = CFrame.new(Vector3.new(Mouse.Hit.X, char.HumanoidRootPart.Position.Y - 1, Mouse.Hit.Z))
	end
	newTS.Orientation = Vector3.new(0,0,90)
end
					
connection1 = Mouse.Move:Connect(move)

Hello, here is the edit:

local max_distance = 10
local function move()
	local vector = Mouse.Hit.p - char.HumanoidRootPart.CFrame.p
	newTS.CFrame = CFrame.new(vector*math.clamp(vector.Magnitude,0,max_distance)+char.HumanoidRootPart.CFrame.p)
	newTS.Orientation = Vector3.new(0,0,90)
end```

Forgot to explain, so I used math.clamp to keep vector length less than max_distance and bigger than 0.

I tried your method and now the outcome is much different.
https://gyazo.com/a36935b13c63bf3a4c7444bf91032b65
You can’t even see the small circle this time.

I think you would need a unit vector to control the magnitude using OwOshka’s method…
Something like…this??? Not sure…

local max_distance = 10
local function move()
	local vector = Mouse.Hit.p - char.HumanoidRootPart.CFrame.p
	newTS.CFrame = CFrame.new((vector/vector.Magnitude)*math.clamp(vector.Magnitude,0,max_distance)+char.HumanoidRootPart.CFrame.p)
	newTS.Orientation = Vector3.new(0,0,90)
end```
1 Like

My bad, here is the fix:

local max_distance = 10
local function move()
	local vector = Mouse.Hit.p - char.HumanoidRootPart.CFrame.p
	newTS.CFrame = CFrame.new(vector. Unit*math.clamp(vector.Magnitude,0,max_distance)+char.HumanoidRootPart.CFrame.p)
	newTS.Orientation = Vector3.new(0,0,90)
end```
1 Like

Thanks for the help m8 my issue is now resolved!