Add limit on Body

Hi ! So actually i maked a script just make npc Follow me like this

But, i I would like there to be less distance between me and the npc except that, I don’t want it to move faster
I try to mix my script with other script on the form using BodyPosition and Gyro but is nor work so i make this post

This is my actual code

--local Run = game:GetService("RunService")

--Run.Heartbeat:Connect(function()
	--script.Parent.CFrame = script.Parent.Parent.Parent:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(3,2,2)
--end)
local Huma = script.Parent.Parent.Parent:WaitForChild("HumanoidRootPart")
local Model = script.Parent
--Run.Heartbeat:Connect(function()
	--wait()
	--local p = Huma.CFrame * Vector3.new(2,2,2)
	--Model.BodyGyro.CFrame = Huma.CFrame
	--Model.BodyPosition.Position = Vector3.new(p.x, p.y, p.z)
--end)



while wait() do
	local p = Huma.CFrame * Vector3.new(2,2,2)
	Model.BodyGyro.CFrame = Huma.CFrame
	Model.BodyPosition.Position = p
end

 --   local RunService = game:GetService("RunService")
     
     
  --  RunService.RenderStepped:Connect(function()
	--local p = Huma.CFrame * Vector3.new(2,2,2)
	--Model.BodyGyro.CFrame = Huma.CFrame
	--Model.BodyPosition.Position = Vector3.new(p.x, p.y, p.z)
    --end)

The comment code line is old version (bad)

1 Like

You want the NPC to be closer to you, or was that a typo?

Yes i want the npc to be closer of me

Just change the

local p = Huma.CFrame * Vector3.new(2,2,2)

code to

local p = Huma.CFrame * Vector3.new(xDistance,yDistance,zDistance)

also regarding those comments I do recommend using Heartbeat over while true do. Since you are wanting the NPC to be closer to you obviously Heartbeat, RenderStepped and while true do both would not effect that result. Assuming you’re using a client script that is, which you should since RenderStepped only works on the client.

1 Like

@serverOptimist I’m talking about the maximum distance when I move like in the post gif, I’m not talking about the default location / final

Try adjusting the D value (dampening) of the BodyPosition. You can also try messing with P and MaxForce if you need to.

When i edit the D value is relly glitchy :confused:
https://i.gyazo.com/16d86323c2f5f2700646bd7fa14a2895.mp4
when i edit the P is work more good bot is alwase mor glitchy
https://i.gyazo.com/a935410e597804c79b8f4ede92758b7e.mp4

Use AlignPosition and AlignOrientation instead of Body Movers. They have constant velocity and they require less scripting.

can you explain to me how to use it?