4
\$\begingroup\$

What's the optimal method in Unity to match the size of a Capsule Collider to the actual size of the game object it is part of?

To understand what I'm trying to do let me give an example:

I have a 3D player character with a Capsule Collider that is used to check collision. The character can go into various postures, e.g. crouch, prone, jump. I'm having difficulties to match the height of the collider to the height of the character when crouching or jumping because depending on the used animations the character's height is smaller by various amounts when crouched or jumping.

All I could do so far is set a multiplier for a specific posture by that the collider scales but this is very inefficient, especially when the character tries to jump onto a higher ground.

There seems to be no way of knowing the exact size of a mesh. I'm not sure if it might help to loop through all child meshes (torso, hair, etc.) in a game object and obtain their bounds through SkinnedMeshRenderer.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Its best to handle collider scalling through mecanim system. Please refer to the following video. The guy adjusts the collider size according to the animation state. It covers the same problem which you are currently facing.

https://youtu.be/Xx21y9eJq1U?t=2161

\$\endgroup\$
1
  • \$\begingroup\$ Awesome! Thanks for the link! This seems to be the solution. \$\endgroup\$ Commented Oct 27, 2015 at 5:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .