Forum rules - please read before posting.

NPC collision

Hello to all!

Sorry if this is kind of a noobish question, but I want to know which is the best way to set the NPC so that my Player does not step over them (I'm creating a 2D Point and Click game, using Polygon Collider, pretty much as the 2d demo).

I know I can make holes on the NavMesh on the spots in which the NPC stand, but this only works (to my knowledge) if the NPC is static. If I want to avoid moving NPC, do I have to switch to Unity's NavMesh and use the NavMesh Obstacle?

Also, back to the Polygon Collider, should my player have a Circle Collider 2D at his feet to avoid the holes or whatever I use? Or should the NPCs be the ones with the circle collider? (or both?)

Thanks in advance!

Comments

  • Please see Section 2.13 of the Manual, which covers the options available for Polygon Collider navigation.

    Your NavMesh's Inspector has a Character evasion option - for performance reasons, this is set to Stationary Characters Only by default, but you can set it to All Characters to affect moving ones as well.

    For character evasion to work, all characters in question (both Player and NPCs) must have Circle Collider 2Ds at their base on their root object.  You will also need to set a non-zero Pathfind update time (s) in the Settings Manager for characters to recalculate evasion paths.
  • edited May 2017
    Ok, I tried this but still found a couple of problems. I'll post the screenshots:

    image
    I set the circle collider 2d in both the player and NPC (in their root object, not the sprite).

    image
    This is the setting for the NavMesh.


    image
    And also the setting of the Pathfind Update Time.


    image
    But in the end, the player still goes through the NPC (here it doesn't look very clear, but a frame before this picture was taken she was behind him, and then they overlapped).


    What could it be that I'm missing? Thanks in advance!
  • It could be that they are too big for them to take effect.  This feature works by automatically removing holes from the NavMesh that have the same shape as the character's circle colliders - and if they go over the NavMesh's boundary then they won't work.

    They will also need to be at the character's origin - i.e. where the Audio icon / yellow circle are.  Set their Centre values to (0,0,0) and reduce the radius by at least half and see if things improve.

    Know that if you enable "Gizmos" in the Game window while playing, you should be able to see the NavMesh update in realtime as holes are automatically generated.
  • 1- I tried with smaller circles first, and it did not work. I'm also made sure they are not going out of the navmesh (the circles).


    2- The circle collider is now centered. But it still is not working (player still goes through the NPC). Don't know if this is relevant, but this scene is the same one in which I'm having trouble with the detection of the holes (this issue in particular: http://adventurecreator.org/forum/discussion/6334/holes-not-detected#latest).
  • It is indeed due to the other issue - you were not using Polygon Colliders for your NavMesh.
  • All good now. Thanks!!
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.