Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to use collider with skinned meshrenderer?

Discussion in 'Scripting' started by Lekret, Mar 1, 2021.

  1. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    272
    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.
     
  2. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,663
    Animations do move transforms at runtime, how would they work otherwise? o_O

    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).
     
    knufix and Lekret like this.
  3. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    272
    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.
     
    Last edited: Mar 1, 2021
  4. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,663
    Glad you got it working! :)
     
    Lekret likes this.
  5. mikeymcmanus700

    mikeymcmanus700

    Joined:
    Mar 4, 2023
    Posts:
    6
    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?
     
  6. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,663
    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.