I’m using a dummy to follow the player, Now there’s one issue, the dummy always wants to be in the players position, so if u stand he will push you out…
Is there a way to make the dummy follow the player but also make him stop like 2 or 3 studs away from me?
The script:
while true do
wait(0.5)
if follow == true then
dummyHum:MoveTo(player.Character.Torso.Position)
end
end
Maybe something like Humanoid:MoveTo(target.Position + Vector3.new(1,0,0))
Don’t know if it works tho, (i can’t test that right now :3)
while wait() do
if follow == true then
dummyHum.CFrame = player.Character.CFrame
end
end
I’m not sure if this will work, as I haven’t tested it in studio and it could be pretty laggy. If this doesn’t work, then you can weld the dummy to the character. This may work better than what I said.
This is also better than MoveTo() because it’s more flexible and allows for you to have more control of the dummy rather than him moving to the player’s humanoid
Ok but you’re still manually setting the CFrame of the model which will result in teleports. What happens if the player turns around 180 degrees? He will teleport so he’s still behind you.
The thread is looking for a follow mechanic where the dummy walks behind the player.
But you’ll need to turn it into a Vector3. I think that’s what @ArtFoundation was trying to say in their reply.
To use your original code with these extra bits:
while true do
wait(0.5)
if follow == true then
local playerCframe = player.Character.HumanoidRootPart.CFrame
local goalCframe = playerCframe * CFrame.new((dummyHum.RootPart.Position - playerCframe.Position).Unit * 2)
dummyHum:MoveTo(goalCframe.Position)
end
end
I changed out a couple variable names to make it a little clearer.
I’m home now and tested this, turns out the dummy still doesn’t stop 2 studs behind the player, he just kinda goes around you, pushes u out of the way etc…
It should be 2 studs from centre to centre, if that happens to be at the side of you and you meet at angles that will probably still result in some pushing.
Perhaps increase it slightly and/or put some sort of condition where if you’re within a slightly larger radius it doesn’t update the MoveTo.
Something like this maybe:
while true do
wait(0.5)
if follow == true then
local playerCframe = player.Character.HumanoidRootPart.CFrame
if (dummyHum.RootPart.Position - playerCframe.Position).Magnitude > 2.5 then
local goalCframe = playerCframe * CFrame.new((dummyHum.RootPart.Position - playerCframe.Position).Unit * 2)
dummyHum:MoveTo(goalCframe.Position)
end
end
end
I’ve tried it and the npc was in front of me so i rotated the subtraction dummyhum - hrp to hrp - dummyhum, and now he’s always on my side or a little to the front
still didn’t get the effect of him being behind me ._.
Thank you for your help tho, if you want to continue trying to find the answer then sure
If you want him to always be behind you, then the script is a bit different - apologies if we misunderstood, but the solution I incorporated was to keep 2 studs away in the direction the NPC was heading towards the player.
If instead you want it to always be behind the player, then you can swap out the goalCframe line with the following:
local goalCframe = playerCframe - playerCframe.LookVector * 2
This uses the player’s HRP’s CFrame.LookVector to determine the way you’re facing, and move -2 multiplied by that to go 2 studs behind.