Hello, I have this script which makes an NPC Bot follow a player. I attempted to make the bot always stay behind the player at a good distance but I had an issue if the player is facing a different direction? How can I make it always go behind the Player no matter the way they are facing.
while FollowMaster == true do if (game.Players.CrazyCorrs.Character.HumanoidRootPart.Position-script.Parent.HumanoidRootPart.Position).Magnitude > 5 then script.Parent.Humanoid:MoveTo(game.Players.CrazyCorrs.Character.HumanoidRootPart.Position-Vector3.new(0,0,-2.3)) end wait() end
The script is cut but anyway I would've instead used CFrames, just do this instead:
local howFar = CFrame.new(0,0,-2.3) local humanoidRP = game.Players.CrazyCorrs.Character.HumanoidRootPart script.Parent.Humanoid:MoveTo((humanoidRP.CFrame*howFar).position) -- now it will be more local than global (more related to the character than everything else). don't forget to do the ".position" because the result is a CFrame (the multiplication of a cframe and a cframe = another cframe) and MoveTo only accepts Vector3.