playMaker

Author Topic: NPC Passing Through Objects  (Read 5439 times)

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
NPC Passing Through Objects
« on: September 26, 2012, 10:47:01 PM »
Hello all.

Have a problem here and it may or may not be a simple fix. I don't know.

I have a player object set up with a rigid body and collider. No problems with the player.

The NPC characters I have are the problem. They are able to walk through each other and walls without any problems. They have colliders that are not triggers and rigid bodies that do not react to gravity but are kinematic. The walls have colliders as well but no rigid body, although I have tried adding them and they are still kinematic. The movement actions I am using are Move To and Move Towards.

Is there a way to stop them from being able to move through walls easily or do I have to add a collision event to where the colliding NPC simply moves to the next waypoint away from the wall if they collide? That seems like a hack and I was wondering if there is a simpler way.

Thanks in advance for any assistance.

cdillard

  • Playmaker Newbie
  • *
  • Posts: 18
Re: NPC Passing Through Objects
« Reply #1 on: September 26, 2012, 10:49:45 PM »
Also, although the player cannot pass through the NPC (this is what I want), this is nullifed because the NPCs are able to pass through the character (Not what I want)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: NPC Passing Through Objects
« Reply #2 on: September 27, 2012, 01:05:44 AM »
Hi,

 I think you could get away with some layer collision physics layer tricks.
http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

for your walls, maybe a way point and path finding framework would help here.

bye,

 Jean

DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
Re: NPC Passing Through Objects
« Reply #3 on: October 24, 2012, 11:39:49 AM »
Why do your NPCs have kinematic rigidbodies? They should be non-kinematic since they're actually moving. Moreover, your setting won't detect any collision, since static colliders (as you have your walls) won't collide with kinematic rigidbodies with colliders. Setting your NPCs as Rigidbody colliders will stop them to walk through them, as well.

http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html

You can as well detect collisions based in layers, so your walls can detect whether the collider object is a player, or NPC, or foe, or whatever category you might want.

http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

For the waypoint... Rudimentary, just wait until collision, then just turn back at any rotation backwards (so you can give it some randomness), and have your NPC to walk that direction. You might want to randomize your rotation as well at some times while walking. Or, you can follow jeanfabre's suggestion and look for a pathfinding framework.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8