Forum rules - please read before posting.

How can I make the player walk across my NPCs in a 2D direct control game?

The game is a 2D, direct-controlled game (using WASD) My player and NPCs all use rigidbody 2D components and circle colliders for their feet, so that they can walk up and down slopes (and follow the player at times) - The NPCs are not static

But when I walk across the NPCs, my player's circle colliders collide with theirs, pushing them along as I make the player walk. How do I go past them, as if they were behind the player? Thanks!

Comments

  • Rigidbody and Circle Collider 2D components aren't necessary for 2D characters to walk, only for collision and evasion.  If you have no need for those, you can either check "Is Trigger" in the Collider, or remove the components on the NPCs.
  • edited September 2017
    @chrisicebox The NPCs are mecanim based characters (using Sprites unity complex) Removing the collider or checking "is trigger" makes them fall through the floor (box/ polygon collider 2D) I think rigidbody and the colliders would also be required to make them respond to slopes etc right?

    Here's an image:image

    imageimage
  • Interesting approach - normally 2D games work with the character's inside the NavMesh / colliders, not on top of it.

    In that case, placing the Player object on a separate Layer and modifying Unity's Physics settings to have it ignore your NPC root layer should do the trick.  The NPC Hotspot will need to be on Default, but that shouldn't bee the root object anyway, so you should be safe to change the root layer to a new "NPC" layer.

    You may want to tweak the characters so that those yellow circles appear at the character's feet, however, as that is where AC considers their positions to be.
  • edited October 2017
    Oh yeah, sorry I forgot to mention that I'm aiming for a complete sidescroller type game, and have disabled up and down movements (that is, disabled away from and towards the screen) About placing the characters on top of the collider instead of inside it, I think I misunderstood your instructions on how to restrict player movement in direct mode, and ended up doing it this way by accident :P Luckily for me, looks this method works too! 

    On a side note - I would've liked to have the ability to jump but as you told me in a previous question I'd asked, I think that is not possible in AC currently, right?

    I've done as you suggested, and the solution works perfectly :) I'm still somewhat new to Unity so I wasn't aware of the physics settings option.

    About the yellow circles, I wasn't able to change their positions in anyway. I've made my characters using Anima2d, which means I imported the arms, legs, torso and head separately, and made them work together with its bones structure. Due to this, I couldn't find any option to change the pivot to bottom. Should I leave it in the centre if this creates no issues?

    Thanks!
  • If it works, it works - but you should test how it copes with saving and loading before leaving it.  An offset can be introduced by moving your Anima2D rig/sprites to a new child and using the child object to offset it correctly.

    Jumping is not possible in the AC controller because 2D is expected to behave differently to the way you've managed it - but a simple call of Rigidbody2D.AddForce in a custom script could concievable add this on top.
  • Alright, I'll keep this in mind and implement what you've suggested. The suggested solution for NPC collision works, as I mentioned earlier.

    Thanks for the continued help! @chrisicebox :)
  • Hello, back to this post after 1+ year. As @ChrisIceBox said(in the last comment), this method is giving me issues with saving and loading.

    I've set up the characters correctly (root object on a custom layer, child object on default layer) Asking AC to "Auto add save components to Game objects" adds "Remember NPC" to all my NPCs root object. This changes the root objects layer from "NPC" (a custom layer I've set up to avoid collision with my player, as suggested earlier in this thread) to "Default" only during runtime and the player and different NPCs begin pushing each other on contact again.

    Any workaround? Thanks!

  • Let's see your NPC's full root hierarchy in the Inspector. What are his other components, and what are your AC/Unity versions?

  • Ac version -v 1.65.2 , Unity - 2017.2.0f3

    Here are the images

  • Thanks. Already scheduled to be in v1.66 is a fix to prevent the RememberNPC component from affecting the object's layer unless it has a Hotspot component but no RememberHotspot component as well. PM me if you'd like to be included in beta-testing.

  • Sure, will send a PM. Thanks!

  • @ChrisIceBox

    Thanks. Already scheduled to be in v1.66 is a fix to prevent the RememberNPC component from affecting the object's layer unless it has a Hotspot component but no RememberHotspot component as well. PM me if you'd like to be included in beta-testing.

    Hi. Is the above fixed? I need an NPC with a Hotspot and RememberHotspot component, along with a RememberNPC component. This changes the NPC's layer on runtime to ignore raycast, causing collision problems. Any workaround?

  • Perhaps my phrasing could have been more clear. A RememberHotspot component will set the object's layer to either Default ("On") or Ignore Raycast ("Off") depending on the Hotspot state on start Inspector value.

    If you need the root object to be unaffected, just move the Hotspot / Remember Hotspot components to a child object, and give it a Trigger collider. Unless this is also on the sprite-child, be sure to also uncheck Turn root object in 3D? in the NPC Inspector to prevent the Hotspot from turning on the z-axis.

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.