Forum rules - please read before posting.

How to make NPC physical?

Hi how do I ensure that my player bumps into/cannot walk through my NPC's?

Thanks!

Comments

  • In 2D or 3D?  If 2D, find your NavMesh's Navigation Mesh Inspector, and check Attempt to move around characters when pathfinding?, and make sure your NPCs have Circle Colliders on their base object.
  • I have the same question about 3D :)
  • That's more tricky.  If your NPC always stands in the same place, you can just add a hole in your NavMesh.  Otherwise, you can look into attaching a NavMesh Obstacle to your NPC, though you'll also have to make sure you're using Unity Navigation as your pathfinding method.  I can't speak for the success of that, but I shall have a look into that myself.
  • Thanks! I'm not using Unity Navigation at this time and would like the NPCs to move. Will try to improvise.
  • I'm afraid that the npc doesn't seem to be getting out the way I'm afraid and just walks through my character even with the circle collided on the base object. Plus the Nov shows through my player when he is behind him therefore not adhering to the sorting map? They r both set to 0
  • Should my player character have a box collided?
  • The NPC won't get out of the way unless you check Keep out of Player's way? in their Inspector.  The steps I gave above cause the Player to move around the NPC.  You do not need a Box Collider on your Player, but you should have a Circle Collider at his feet + a Rigidbody2D.
  • ok this seems to work now, however, when I do bump into them, and the NPC is on a path, it throws them off it and they just stand still, and to avoid me they can walk outside of the nav mesh?
    any reason as to why this happens?

    Plus, the biggest bugbear of all is that I can't seem to get the sorting layers correct so that I'm not standing on there heads when i'm behind them?
  • The NPC needs to be standing still for the Player to be moving around them.  NPCs shouldn't leave the NavMesh - you're using v1.49?  There are some issues reported with 2D NavMesh's that I'm looking to fix ASAP.

    As for the Sorting Map issue, I need to know more about it.  Please post screenshots of how you've set up your Sorting Map, and your FollowSortingMap components - giving me as much detail as possible for me to give you a proper solution.
  • I am using v1.49 and the NPC moves out of the nav mesh to get away from me and then never returns to the path loop once i move out the way.

    re Sorting Map, see screenshots below of sorting map inspector and NPC. In all scenes the NPC's stand on my head or I stand on there head.

    My player is set to 0 order in layer and has Follow Sorting Map ticked, Offset original order and also affect children ticked.



  • The NPC shouldn't try to evade the player if they're already moving on a Path.  You might need to send me the scene so that I can see this for myself.

    Does the sorting issue only occur when both characters are in the same vertical sorting region, or also when they're in separate?  Check that the sprites are indeed what they should be: i.e. 1 when at the top, and 9 when at the bottom.  If two characters are both in the same region, you should see their sprite child's be offset ever so slightly in the Z-axis (e.g. 0.001) to correct the display.  Is this happening?
  • The characters are following the sprite map correctly, I see this in the order layer for them when in play.

    I am seeing teh offset happen too, it seems better now since I have added more areas.
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.