Making Colliders/Triggers or Rigidbodies move a Character Controller

There seams to be a general consensus that the preferred way to affect a character by either animated colliders or rigidbodies is to not use a character controller at all. Unfortunately at this stage of the project, many of the developed character scripts have been specifically based on the constraints and behavior of a character controller. Further, implementing a rigidbody controller setup from scratch is not feasible at this point.

We are exploring alternatives and looking for opinions on this topic, so please feel welcome to add your input and comment any ideas or suggestions you feel are relevant. Here are our possible solutions:

  1. Set an animation state which is triggered during collision with tagged moving objects, eg. an opening door, moving traffic etc, causing the character to fall or be moved aside via animation.

  2. Switch to rag doll upon collision, creating rigidbody collisions, before blending back to the animated character.

  3. Add a rigidbody component to the character controller and have it add force to the collision objects, except making the force value negative.

  4. Parenting the character upon collision (similar to the technique used for moving platforms), and perhaps having the unparenting controlled by a timer. This solution has not been looked into extensively and is merely an idea at this point.

If you have prior experience in similar character setups or interactions please comment which suggestion you feel is the most useful, or supply your alternative instead.

From the team, thank you.

Well, the only advantage beside the many disadvantages a CharacterController has is that it’s NOT invluenced by other objects. A CharacterController is not a phyics-controlled object.

It strongly depends on how much you want to put the control of your character to something else. If you move it manually it propably doesn’t look “real”.

  1. This is hard to do because you in most cases the movement depends on the relative position to the other object. A rotating door moves faster outside than near the hinge.
  2. I don’t see how this should work. If you turn your character into a rag doll every part of your character moves on it’s own. The model will “fall” out of it’s CharacterController-GameObject. Rigidbodies are always simulated in worldspace.
  3. I don’t get the negative thing… What force you want to invert and apply to what object?
  4. This can work out in some cases but generally can produce very strange behaviour.

If you really want to stick with your CharacterController you have to decide in each case what’s the best way. The most general way is using a Rigidbody :smiley: That’s why we have a physics system.

However in our Hack&Slash game we also used the CharacterController. We also have a special case where the character is under foreign control (a push attack). This effect is integrated in everything (to prevent player movement and to apply the push force). It’s not a very nice solution but most of time we’re happy with the nature of the CharacterController. We also thought about using a Rigidbody controller, but we had even more problems so we stick with the CC.

Well some thing doesn’t work very well, like the slopelimit, but we have a custom solution for that ;). All in all the CharacterController is not that bad but if you want a mixture of direct control and physics you propably should use a Rigidbody.

Just to be clear: There’s nothing that can’t be done. It’s always a matter of effort you put into it. You don’t have to use PhysX, you’re free to calculate everything on your own if you know how :wink:

Finally i’d like to say that i’m not sure what you expect as answer. It seems that this “question” tries to start a discussion which is something that should be posted on the forums instead. UnityAnswers is for clear “questions that can be answered”.

For those people still interested in moving a character controller via an impact based collision system, I would highly recommend looking at the old third person shooter demo.

There is a script on the Hero character which moves the character a specified distance whenever they are struck via raycast by the enemy bot. Maybe someone can take this and turn it into a more useful onTriggerEnter/OnCollisionEnter script. That’s all it would take.

If I were you, I’d forget about character controller entirely. Personally I think the character controller driven models look terrible.

I’d recommend using blends animations from the artists for character movement, driving the speed of the animations based on move speed. Where you want a ragdoll for collisions and stuff, I’d suggest jumping into ragdoll on collision, and then transitioning out of ragdoll by interpolating the model into the start frame of one of a few “get up” animations.

If you want to see an example of a (non-unity) game that uses the same approach, check out wolfire game’s overgrowth:
http://blog.wolfire.com/2011/04/Overgrowth-a126-video-changelog

This has the virtue of being local to your characterScript. It works, but not sure if it can be tuned to look nice. Toss a slightly larger triggerbox on your character, then:

Vector3 pushAmt; // global "pushed by RBs" accumulator

void OnTriggerEnter(Collider cc) {
  Rigidbody rb = cc.rigidbody;
  if(rb!=null) {
    pushAmt += rb.velocity*0.5f;	
  }
}

PushAmt is added to the final move in FixedUpdate:

moveDirection += pushAmt;
pushAmt*=0.95f; // fake friction

Other options (untested) are to have OnTriggerStay also do it, so an object can give a continuous push instead of only a shove. The animation could be triggered by the final move – walking backwards might look the same if we were gently shoved, or doing it on purpose. Could have OnTrigger also play a “flinch” for sufficiently large new pushes.

Also the option of checking for specific tags (“doors” objects always shove you directly away from them, at speed X, say.)

Would just like to add here, for those using the character controller <—> ragdoll setup, a good way to transition from ragdoll back to the animated character is to animate the ragdoll into a transition animation. To do this one can turn the ragdoll rigidbodies to kinematic and then animate them the usual way until in a position to switch back to the CC.

Hope that helps.