Search Unity

Best way to have a compound collider player and get precise collisions?

Discussion in 'Physics' started by MDragon, Jun 17, 2015.

  1. MDragon

    MDragon

    Joined:
    Dec 26, 2013
    Posts:
    329
    Heya there~

    As a bit of context, I'm trying to make a sort of mech flying game (in terms of gameplay- humanoid, "free" quick flying). One aspect I'm working on is precise collision detection- the player can move around, but if shot at say in the legs, I can detect that the leg was precisely shot (and thereafter add some rotation, make the leg unusable/break off, etc).

    The first solution I thought of was to use the character controller. However, how would I use a compound collider with that? (as the character controller itself has a single capsule collider). A quick solution I could think of to this sub-problem...
    • Use the character controller, give it its own layer
    • Make the compound colliders as necessary, make them all on one specific layer
    • When projectiles, raycasts, and such look for the player, make them ignore the character controller layer completely (although NOT specifically look for the compound collider layer, as then the projectiles and raycasts may go through walls)
    On the other hand, I thought of another solution: Use a rigidbody, with compound colliders instead. I know how to use a rigidbody and colliders by themselves quite easily, and I don't have to worry about the additional complexity of two collider layers. However, I can't use the Is Kinematic option, and thus would have to use forces+velocities to move the player around (as I could have other objects in the environment that have colliders and use the Is Kinematic option, but then the player and those objects would not collide due to how the engine works).

    Ultimately, what would be the better solution here? I'm not sure if there are any big factors I'm missing here between these two solutions. For example, I'm definitely going to be using player animations down the line (as well as IK). However, I've never animated a rigidbody with active colliders and accurate collisions, so I have no idea if the complexity would be worth it.

    Thanks!