Forum rules - please read before posting.

NPC follow - but always stay on left side of Player


I was just wondering if there was some easy shortcut to making an NPC follow my player character, but in the following way:
The NPC stays on the same side (left) of the player all the time at a certain distance. So when the player walks right, the NPC will follow at X distance. When the player walks left the NPC will move left immediately and keep the X distance from the player, instead of letting the player pass him and then follow.
Maybe there is a comparatively simple way to achieve this by editing the existing NPC follow code...?


  • This should be possible with a custom script, attached to the NPC, which works by moving the NPC to a set distance from the Player whenever the Player moves.

    This would replace the use of AC's Character: NPC follow Action, so you'd need to remove those for it to take effect:

    using UnityEngine;
    using AC;
    public class NPCFollowOffset : MonoBehaviour
        public NPC npc;
        public float offsetDistance;
        private void OnEnable () { EventManager.OnCharacterSetPath += OnCharacterSetPath; }
        private void OnDisable () { EventManager.OnCharacterSetPath -= OnCharacterSetPath; }
        private void OnCharacterSetPath (Char character, Paths path)
            if (character == KickStarter.player)
                Vector3 npcPosition = path.Destination + Vector3.right * offsetDistance;
                npc.MoveToPoint (npcPosition);
  • Yes, that works perfectly for me.
    Thanks for great help as always!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.