Search Unity

Character Controller and Physics.Ignore()

Discussion in 'Editor & General Support' started by MatthewW, Apr 7, 2007.

  1. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Just for fun, I'm making a game about hunting raptors from helicopters. I'm using a CharacterController to move my raptor around, and then when the player hits it the physics rig takes over.

    The ragdoll rig is set isKinematic=true and detectCollisions=false while the raptor is alive.

    I want to use the ragdoll rig for collision detection with the world for accuracy and feel reasons. However, when I set detectCollisions back to true the CharacterController no longer moves. Telling it ignore all of the ragdoll colliders via Physics.Ignore() doesn't resolve the situation.

    Is CharacterController doing raycasts or other things internally to move around? Any tips?

    Here's the rig (when detectCollisions=true it just floats in midair):
     

    Attached Files:

  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Never mind--most of my problems have been solved by using OnControllerColliderHit() instead of OnCollisionEnter() to detect collisions with the Character Controller. Should have noticed that earlier!

    I'd still be interested to know if it's possible to have the Character Controller ignore collisions with specified objects, though...
     
  3. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    I still can't get it working reliably. Sometimes you can push the raptors for a few seconds before the collision is detected.

    http://www.flashbangstudios.com/tests/chopper4/

    Should I just switch over to a rigidbody with fixed rotation?

    Here's what I'm using to detect hits with objects that should kill it:

    Code (csharp):
    1.  
    2.     // when our collider bumps into something
    3.     void OnControllerColliderHit (ControllerColliderHit col)
    4.     {
    5.         // only care about moving objects
    6.         if (col.rigidbody == null)
    7.             return;
    8.  
    9.         // did we hit a kill object?       
    10.         foreach(Rigidbody rb in Game.instance.KillObjects)
    11.             if(rb == col.rigidbody)
    12.                 GameKilled();
    13.     }
    14.  
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Looks really awesome.

    The character controller doesnt support ignore collision right now.

    Why not make raptor colliders a trigger, when not in ragdoll mode.
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    If you want all collisions between box and character controller.You need to support both oncontrollercolliderhit and oncollisionenter.

    Eg. when the character moves into a box it will call oncontrollercolliderhit and ensure they are not penetrating anymore. When the box is simulated, it will call oncollisionenter.
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    This really looks awesome. Very cool effect on the grass and nicely tuned ragdoll effect on the raptor, just gotta love picking them up with the wrecking ball.
     
  7. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I love it too! Nice!
     
  8. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    the moving grass is fantastic - very well executed ; )
     
  9. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    Yeah that is really really cool. You should make the raptor have more mass relative to the heli, and make him struggle more. Maybe run away faster and dodge when he hears you coming.
     
  10. Joe ByDesign

    Joe ByDesign

    Joined:
    Oct 13, 2005
    Posts:
    841
    Very cool, and already it is fun! Looking forward to this one :)
     
  11. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Thanks for the feedback guys! I didn't intend to show this so soon; it's is the result of the game jam we had last weekend. We had a bunch of guys get together to work on projects over two days (the other two playable projects that came out of it are here).

    It turns out that hauling raptors around with a Chinook is far more fun than it should be, though, so I'm going to work on completing the game loop as I find more time.

    Forest: The raptor actually weighs a bit compared to the helicopter. If you can flip him on top you'll notice it more--you actually can't fly up with one sitting on top. The chain of hinge joints for the rope has a bizarre way of reducing the effects of mass, though (I think it's lost in the dampening).
     
  12. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Nice job! It was much more fun than I would have expected. It is well executed. The helicopter has a nice feel to it. I could not help laughing while playing. You should flesh this out to a complete game, there is so much you could do with this start :D
     
  13. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Is that the poser raptor? This has been said before, but there are licensing issues with poser content. Dont mean to be a downer, but..better you know now rather than at your release party...
    AC
     
  14. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    Nope--custom-modeled and rigged in Maya...
     
  15. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Prreeemo!-

    Just didnt want you to get in the s@#%

    AC
     
  16. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
    That's cool--I appreciate the concern. We're really careful about rights. I do a lot of work with friends for fun projects like this, but we prefer to pay people outright when something goes commercial (we'll be doing a web version of I Hate Clowns soon, so paid the artist for his time on that).

    Plus, people always act more professional when you're paying them ;)