Forum rules - please read before posting.

NPC gets 'pushed' [2D]

edited October 2014 in Engine development
I'm probably doing something wrong here.

I've put my NPC in the scene but my player is able to push them about.

Creating a Navmesh hole seems like a bad idea because the NPC needs to move at some point. What's the way to prevent this?

Comments

  • edited October 2014
    What I did to fix this was to change the NPC's Rigidbody 2D mass to something ridiculously high (in my case 10000) and that kept my character from pushing the NPC around (he was just too heavy).

    Might have unwanted consequences, but non that I have noticed yet.
  • Thanks.  999 was sufficient it seems.

    However, now the player still tries to get to the spot the NPC is on and does the 'infinite walk' into the NPC until you point them somewhere else.
  • Oh yeah, I haven't interacted with the NPC's with colliders in a while now so I totally forgot that happens :(
  • If the player's stuck because the NPC is in the way, consider lowering the "Destination accuracy" slider in the Settings Manager - that'll mean the player won't try to be so close to the target when walking.
  • Hi Chris, this doesn't appear to help. I had this set to 1 and tried lowering as suggested, but even 0.1 and it doesn't change the outcome.

    Looking at the path calculated in the scene view at the same time it appears to basically run a path through the NPC to the destination and won't stop until it gets there, which it can't.
  • well, one workaround would be to change / add a hole to the navmesh where your NPC stands, but i admit its a problem (hence my dumb questions about pathfinding all the time :) )
  • For now, until there's a good solution, I've gone in and added holes for the static NPCs I have, but for the ones that are moving around I have just removed the collider entirely. I find it far less jarring to have my character pass through the NPCs as if they were ghosts than have them get stuck in the walking animation.
  • I can't help but wonder if attaching a trigger or trigger script to the NPC and having that trigger a stop to the player character would do the trick.
  • edited November 2014
    There's a point in Da New Guys where the player can switch between multiple characters, who may or may not be on the same screen.  Because the player had total freedom of control, it was possible to place one character in front of a doorway, switch character, and then find yourself unable to leave because the doorway was then blocked.

    To counter it, I wrote a script that caused the NPC to move away by small small amount if the player got too close.  Would something similar be appropriate here?  Since that was a 2D game, the character would move towards the centre of the screen if they were on the edge, to prevent them walking off-screen.  Not sure how that would translate to 3D.
  • I think we are all talking about 2D games here. At least I am :)
  • Chris, I think in terms of solving the infinite walking problem that perhaps a solution of recalculating the path to destination when colliding, where the calculation takes into consideration the collider's collision area. If the only path found results in going through the collider's collision area or outside the nav mesh, then stop the character exactly where he is.

    More difficult but I think it solves it for good. I was thinking of doing a script that stops the player when hitting collision but the side effects would be horrible.

    Also as for the pushing issue you could also remove the RigidBody2D but keep a collider on the NPC.
  • In 1.40, NPCs will be able to move out of the way if the player gets too close.  That's a nice solution @WillG, but quite a complex one.  It won't be in for 1.40, but perhaps a later release.
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.