Forum rules - please read before posting.

How best to avoid player clipping/Walking through NPC in 2d.

Hello,

I have a scene with 2d art and with 2d characters, but there is depth movement. (So similar to 2d demo.)
I usually have several NPC standing in the room and they mostly stand still and sometimes get teleported to different spots for cut-scenes.

I'm using polygon collider pathfinding.

Now the problem I have is that player can walk right through the NPC, even stand exactly where NPC is standing. So I was wondering if there is any built in function to prevent player from walking through NPC's and also to handle the Sorting map layers automatically?

Or do I have to create Nav mesh holes and use sorting map for NPC's ?

I built NPC using the wizard so they have the circle collider etc.

Thanks,

Comments

  • I didn't use it myself yet, but you could use Unity TransparencySortMode on the Y axis.

    https://docs.unity3d.com/ScriptReference/TransparencySortMode.html
  • Thanks, I'll check this out. If it works that should solve the sorting layers, but that leaves NPC standing spot avoidance sort of.
  • In your Navigation Mesh inspector, you should see a Character evasion option.  This is set to Stationary Characters Only by default, but can be set to All Characters if your NPCs are moving.

    At runtime, you should see your NavMesh update automatically with "holes" around your NPCs when the Player moves.  Try having your Scene window open beside the Game window - do they appear when the NavMesh is selected?  The NPCs will indeed need Circle Colliders on their feet, but it sounds like that's all set up correctly.
  • Thank you, that seems to work!
    And for sorting I should do it manually right?
  • So long as they're on the Sorting Map, the sorting should be automatic.

    When two characters are in the same Sorting Map area, the Z position of one of them should be automatically changed ever so slightly so that it's not in the same plane as the other, causing the correct display order.
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.