Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part Following You?

Asked by 10 years ago

I have,

dist = (Torso.Position - pos).magnitude
if script.Parent.Postion < dist then
    script.Parent.Postion = dist
end

but I can't seem to think of anyway to get it to follow at a distance of 3 and follow a set person. Ex: YellowTide.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

The simplest architecture for this problem looks like this:

local distance = distanceToTarget;
-- distance to target would probably be
-- (myposition - targetposition).magnitude

if distance < followDistance then
    -- I'm close enough
    STOP();
else
    -- I'm further than
    -- followDistance away
    GoTowards(target);
end

Depending on the type of thing you want, how you would "stop" and "go towards" could be very different. For a Humanoid "stop" would just MoveTo the position the humanoid is already at, and "go towards" would just MoveTo the target.

Your "target" would be, in this case, the position of the player ('s torso) you are assigned to. This could be related by either ObjectValue references (or equivalent references through _G), StringValue, Name, or other player-name based ways to reference them (through game.Players[PlayerNameVariable]), or by a parent relationship (the model following is a descendant of the player's character).

0
This help very much. Gotta love all the helpful people here at SH. YellowoTide 1992 — 10y
Ad

Answer this question