Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.