I’m working on a game that plays similar to the Mario & Luigi RPG series, where the second playable character is always following behind the player in the overworld outside of battle.
The general idea is that the second character will stick behind the player and follow them around automatically, but certain actions (such as jumping) will require player input. The player should not be able to split up with the second character normally, the Mario & Luigi series prevents it by stopping the player from moving if they attempt to move when the second character cannot follow them.
Here’s a video that should hopefully showcase what I’m aiming for (timestamped at 41:40 because it’s a playthrough of the entire game lol)
I’m just gonna add on to what @Cozmicweb has stated.
Basically on every frame, you need to check the distance between the Player and the NPC.
If the distance is greater than a threshold, compute a path to the player and move the humanoid.
RunService.Heartbeat:Connect(function(): ()
--// example, replace with actual code lol
local Distance = (Player.Position - NPC.Position).Magnitude;
if (Distance > DistanceThreshold) then
--// compute the path and move to the player
--// make sure not to compute the path too many times
else
Humanoid:MoveTo(RootPart.Position) --// stops the character
end;
end);
If you want the ‘NPC’ to be another player, it’s 100% possible, but it’s a bit hard to get it to work. I believe for players, it’s better to weld them because physics constraints replicate very smoothly.