Forum rules - please read before posting.

NPC Follow: teleport to player’s range if stuck

Hello folks!

I’ve been using AC for about two months now and I absolutely love it!

I recently tried the Npc Follow action which worked just as intended until I started to push the boundaries of my game looking for bugs.

I then noticed that sometimes the npc following the player gets stuck in a corner or something and because of that, ends up ruining the experience.

Is there any easy way to tweak “npc follow” so the npc teleports to player if, lets say, the distance between them two is beyond a certain limit?

Thank you in advance!

Comments

  • Welcome to the community, @Biali.

    As the exact behaviour would need to be very specific for your game, this'd involve a custom script. Essentially, you'd check the distance between the Player and the NPC, and then teleport them to an appropriate spot.

    The distance check isn't difficult, and neither is teleporting in general. The real difficulty is in picking the "right spot" to place the NPC at - you'd need to involve some complicated Raycasting to find a good place that's near the Player but isn't going to end up with the NPC stuck in the wall or something.

    I'd suggest attacking the original issue, where the NPC is getting stuck on a corner.

    Is this for a 3D game, relying on a baked Unity NavMesh? Try raising the Agent Radius in your Navigation tab, so that the baked NavMesh's boundaries aren't so close to the walls.

    It's also worth noting that - unless your game relies on Direct movement - your walls don't typically need to have solid Colliders on them, which is likely what the NPC is getting stuck on.

  • Hi Chris! Thank you very much for the tips! Indeed the navmesh approach was spot on! It seems to have solved the problem! Thank you a million!
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.