Hello, I’m adding an offset to my path finding. Only problem is I can’t just do + Vector3.new(3, 0, 3) because it will always be that. So how can I get the closest position within the radius.
So basically imagine a circle around the npc. How would I get the closest position in the circle?
Current Script:
local humanoid = npc:WaitForChild("Humanoid")
local rootPart= npc:WaitForChild("HumanoidRootPart")
local rotatedOffset = (targetRoot.Position - targetRoot.Position).Unit * offset
local Goal = targetRoot.Position + rotatedOffset
The problem with this script is there’s no offset.
I’m confused here. Do you want a (random) point within a circle with a given radius. The closest position in the circle, to the NPC would always be the current position of the NPC?
Or do you mean the position in the circle that is closest to the player?
I see. Try this function. It uses the lerp function (Linear interpolation) to get the point that is between a, the target, and b, the NPC, offset by the radius, r.
function GetPoint(a : Vector3, b : Vector3, r : number)
return (a:Lerp(b,((b-a).Magnitude-r)/((b-a).Magnitude))) -- Lerp between a and b, with alpha value dictated by radius (Must be between 0 and 1)
end