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

How do you move an NPC relative to one side of a character?

Asked by 7 years ago

I have a sheep that is supposed to follow behind the player when it is captured, which it does, but it the code I have only set it to stay behind the character on one axis at all times so it often looks strange when the player turns it's torso around, the sheep still follows from that same first direction. Is there a way to have the sheep follow relative to one side of the player instead of along an axis?

repeat
    -- The position of who possesses the sheep.
    local followerPosition = hit.Character.PrimaryPart.Position

    humanoid:MoveTo(followerPosition - Vector3.new(0, 0, -5))
    wait()
until isBlueSheep == false

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 6 years ago

You'd have to simply not use an axis. This should keep it 5 studs away

repeat
    -- The position of who possesses the sheep.
    local followerPosition = hit.Character.PrimaryPart.Position
    local mypos = --SHEEP POSITION
    humanoid:MoveTo( followerPosition+(mypos-followerPosition).unit*5 )
    wait()
until isBlueSheep == false
0
This didn't seem to work as it sent the sheep running off in a straight line away in one direction. I found that the <.unit> seems to be used to derive a vector for velocity. The issue is that it doesn't even send the sheep after the player's position. DavidNate1 10 — 6y
0
Sorry david I messed up. I only gave it the unit, causing sheep to go near the world origin. You have to add it to target's pos. Fixed now cabbler 1942 — 6y
Ad

Answer this question