Hi everybody,
For my game I'm quite satisfied with ork's default player controller and I'm ok with Unity's character controller. My only problem is I have a few characters for which the y-axis oriented capsule collider from Unity's CC can't be used.
I didn't want to create a new character controller from scratch, as I was fine with what I had, I just wanted to have the option to edit the collider shape or, alternatively, to add another collider to my mesh. So I wrote a little script to manage kinematic collisions in case of another collider attached to a game object with a character controller. This is definitely a dirty solution, but it's also quick and easy, so I figured I'd try to manage to see it through.

This is the result:

I have a game object with a character controller, a capsule collider + kinematic rigidbody (obviously with a different shape from the one in the character controller), my collision manager and a simple movement script. This works the way I want it to (with a few tweaks to do, of course). The same setup doesn't work if I recreate it on a character with the default player controller script in place of my simple movement script (I guess that's to be expected) running in game. What happens is the second collider doesn't seem to push back the player object while moving inside obstacles, but if I stop the player with the second collider penetrating an object, it gradually moves outside:
Before penetration:
https://www.dropbox.com/s/ap3wyevmkdfzjb3/Screenshot 2017-09-05 20.24.18.png?dl=0

During penetration (key pressed and movement happening). The character isn't selected to better show the debug points marked by the crosses (capsule collider calculated point 1, point 2 and center. These are the CALCULATED points, where the collider is supposed to be, but the actual collider is penetrating the object):
https://www.dropbox.com/s/5nixd8idfe7gei0/Screenshot 2017-09-05 20.24.33.png?dl=0
Key released and movement stopped:
https://www.dropbox.com/s/729vhk9omevgq8e/Screenshot 2017-09-05 20.24.39.png?dl=0

I guess my question would be.. can this be done? Or should I discard this approach and write my own player controller?

A few info on my collision manager script:
1) everything (collision check, pushback calculation and resolution) happens in a FixedUpdate();
2) the collision is detected through CapsuleOverlap and the colliders are fed to the relatively new Physics.ComputePenetration method
3) the pushback happens through the gameobject's transform.Translate()

Thanks for you help!
  • Is there a rigidbody involved somewhere?
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited September 2017
    Yes, the player object has a rigidbody associated with the capsule collider. It's more of a habit though, as it has no role in the collision manager script. I think the script would work the same without it. I'm not sure if the performance issue with moving colliders without rigidbody is still an issue though. Then again, my game is very cheap in every aspect except maybe image post processing
    Post edited by azazello on
  • Well, in any case you'll probably have to write a custom player controller that serves your needs. If moving via character controller (which is what the built-in button player controls do) doesn't cause the attached colliders to collide with anything, you'll have to write your own controls, e.g. moving through the rigidbody component.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.