How to use collider with skinned meshrenderer?

I have 3d character with sword in hand. I want Box/Sphere collider on my sword mesh do detect hits during attack animation, but it obviously don’t work since animations don’t move transform positions in runtime. I searched, but couldn’t find any working solution.

Animations do move transforms at runtime, how would they work otherwise? :eyes:

Just make sure you’ve parented the collider under your character’s arm hierarchy, so that it moves with it. This is the usual approach. (And if you’ve checked “Optimize GameObjects” in the character import settings, make sure you’ve exposed the arm transforms in the character import settings, don’t optimize them out).

2 Likes

Yes, I found bones property on my skinnedMeshRenderer, found that bones are transforms, tried to set my collider as parent and it worked. In attempt to find where is my collider I found all other actualy moving bones, god why I’m so silly. I tried many approaches, tried to move vertices from renderer to mesh collider, and the approach was so simple. I’m new to animation and didn’t know that object skinnedmeshRenderer don’t move himself, but have large transform hierachy for that.

Glad you got it working! :slight_smile:

1 Like

Late to join this, but I’m working on a similar thing. I have the free minotaur asset from the store. The minotaur game object has a axe child and root child. the axe child is just the skinned mesh renderer but there is a bone for the axe which is just a transform underneath the root gameobject. If i wanted a mesh collider of the axe that would move when animated how would i go about that?

Just parent a collider to the axis bone. Note that it can move, but it cannot deform (that is, it can’t change its shape). Deformable colliders simply aren’t a thing, since that would be out-of-this-world expensive.

I have 100 bones, I created mesh collider for it.
But in game if i move any Bones(charcter), Collider doen’t Follow,
People on reddit suggested to make seprate colliders for each bone
BUT I don’t have the strentgh and capacity to create box colliders for each bones. Does unity have an easier way to do this.

(1) You should make your own thread, instead of raising an old dead thread.

(2) MeshColliders are not deformed by bones. No getting around that. Have to use colliders on bones if in your game, you need colliders to move.

(3) Not every bone needs a collider. Ragdolls would need a collider on long bones like shin, femur, radius, humerus, skull, and a bigger collider to cover the whole torso. Hitbox colliders are usually just a big collider for body, a smaller one for head, and maybe one on each hand and foot for fighting games.

(4) If you can’t handle adding colliders to bones, not sure what to tell you. Game Development is work. If you think you can script an automation for the work, make the computer do the work. If not, get busy yourself.

1 Like