Forum rules - please read before posting.

Multiple NPC follow issues

Hmmm - this is a bit complicated and might require heavy custom scripting to work well, but here goes ...

I'm working on a prototype for my new project which features two NPCs following the player character through most of the game. I've recorded the following video of a test scene with placeholder characters showing some of the issues I'm facing with this:


1: I'm using Unity navigation with each NPC having a NavMesh Obstacle set to 'carve' when stationary, which works quite well for having the player character choose a path around them. There's however the problem that they tend to choose weird directions for the first part of their movement, apparently trying to escape the navigation mesh hole they've created for themselves, as it were. Ideally, the NavMesh Obstacle should be turned off immediately before they do their pathfinding - does that sound like a sensible approach?

2: Ideally, the NPCs should end up facing in the same direction as the player character at the end of their movement in all situations - is there a simple way to do this that I've overlooked?

3: There's a slight jerkiness to the NPC animations whenever the "follow player" logic updates. In the video, the update rate is set to 1 second - anything lower gets quite unbearable. Is there a way to fix this without replacing the whole pathfinding logic?

Also, I'm thinking about making the NPCs aware of each other somehow, to make their movement look more natural. Probably some simple version of a flock behaviour.

I think that's it for now - any ideas much appreciated!

Comments

  • 1) That sounds plausible.  You can detect whether or not a character is moving or not by reading it's charState variable.

    2) No, but it's possible this could come in an update.

    3) I'm not sure if that's because of the animation, or the movement.  It may require tweaking of your Mecanim transitions and/or your movement values in the NPC inspector.
  • 1) I actually managed to fix this now simply by setting "pathfinding update time" to a really low, but positive value. Movement looks much more nautural now.

    2) That would be cool!

    3) OK - will fiddle around with this a bit and see if that solves it.

    After testing this whole setup for a few hours, I realise that having multiple following NPCs introduces quite a few issues that must be taken into account in the scene design to avoid movement deadlock and other nonsense .... :-?
  • Bringing this up... Simply because when I've an issue I search AC forum for keywords.
    This case the keywords were "two NPC follow". So, here is the thing. I'm doing some tests for my new game with 2 NPCs following the player (final game you can have up to 3 NPCs following the player), and the thing is: they are pushing each other to reach player, causing weird behaviors.
    The game is full 3D, with rigid bodies, colliders, etc. And if I set the same min distance for both the NPCs to follow, what's happening is that the first arriving stops at let's say 2 units, the NPC behind him is therefore "pushing" the first to get also at 2 units distance, causing the three to move like a train when my player stops (last NPC pushes the first, that pushes the player... hurray!)

    Is there a way to avoid this? I'm carving the NavMesh when stationary (but can't do while moving, because it creates a mess), this mean also that when the first NPC arriving near the player stops, it's carving the NavMesh and the second might go nuts...

    Should I make one of the NPC to follow the other NPC instead of player?
    But what if those NPCs can change dynamically based on Player options? Meaning, if I've max to 3, could be that one time I've A and B, another time I've only B, then I've A, B and C, one time I've just B and C, etc... How can the "follow each other/follow player" be handled in that situation?

    Thanks!

  • My game is a lot simpler because it's 2D and there are no collisions, but I'm also working with two followers, and I did exactly what you suggested: NPC 1 follows player, NPC 2 follows NPC 1.

    I have one global bool for each follower (true if they are supposed to be following right now), and an actionlist that checks for every permutation and tells the NPCs who to follow. If NPC 1 is missing, NPC 2 follows the player instead, etc. This would grow too complicated if you added more followers, but I reckon 3 is still doable.

  • You can check Randomise position? in the Character: NPC follow Action to have a character move to a random point in a circle that surrounds the Player, as opposed to the nearest point. This should help with the "train" issue.

    For NavMesh carving, you may want to rely instead on NavMeshAgent components, coupled with AC's NavMeshAgent Integration script. IIRC Unity's NavMeshAgents will attempt to avoid one another, though results may vary.

    Having NPCs follow each other is also possible - you'd just need a means of determining, e.g. with variables, which characters are available to follow and affect them accordingly. NPCs can be made to follow another character through script, you're not limited to the Action - see the FollowAssign function.

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.