Humanoid:MoveTo but Creating Spacing in between the point and Humanoid

I have this code that finds the closest player and moves the humanoid toward the player’s HumanoidRootPart.

local closest_root_part = get_closest_in_range_humanoid_root_part();
script.Parent.Humanoid:MoveTo(closest_root_part.Position);

What I want to know is, how do I modify closest_root_part.Position to where it makes the humanoid stop a little early, creating spacing.

Heres a graphic to clear up any confusion

Untitled

local closest_root_part = get_closest_in_range_humanoid_root_part();
local direction = closest_root_part.Position - script.Parent.HumanoidRootPart.Position
local new_position = direction.Unit * (direction.Magnitude - SPACING) + script.Parent.HumanoidRootPart.Position
script.Parent.Humanoid:MoveTo(new_position)

Edit: Forgot to add the vector to the position
Edit 2: Wrong variable

Wow, that was fast. And it works great! Thanks!

P.S: I think you were meaning to use new_position for Humanoid:MoveTo as opposed to closest_root_part.Position

1 Like