Search Unity

Are bone tails kept in unity?

Discussion in 'Scripting' started by Nanako, Jun 21, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    I'm attempting to measure the length of a limb (for example, an arm) by measuring from the head of the first bone (shoulder) to the tail of the last bone, (the hand)

    Thing is, i'm not sure how to do this, or even if i can. I can get the head of a bone well enough, that's just the position of the transform. But i don't know how to get the tail, does that information even exist?
     
  2. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    If you have a joint hierarchy created in your 3D application you can find all the joints in the hierarchy for that model when imported into Unity. So then you should be able to do a Vector3.Distance(jointA, jointB) to get the length between the joints.
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    except if A isnt connected to B, then that only gives the distance between two heads, and not the head-tail length of A
     
  4. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    So I guess you have a joint system that looks a little like this:
    Shoulder
    Elbow
    Hand

    So if you want to know the distance of the whole arm you will need to make a
    float dist1 = Vector3.Distance(shoulder, elbow);
    float dist2 = Vector3.Distance(Elbow, Hand);

    float totalLength = dist1 + dist2;
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    I don't think i ever got a concrete answer for this.

    I need a way to measure the distance between two TAILS of two seperate bones. They're not in the same chain as each other
     
  6. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    The data for the "tail" does not exist in a manner that you can access in any way short of burrowing down to vertex data, as far as I'm aware. Pretty much the ONLY thing you can do to bones directly is expose and modify a single transform belonging to its "head", as you said.

    However, when I modeled my character, I used those little "caps" on the end of the extremities (as well as the top of the head) in order to more easily manipulate the character later. They weren't bones, but they helped control the bones- I'm not really a 3D modeler, so I can't remember exactly what they were called, but I do know that my model in Unity has them listed as "bones" (RightToe0, LeftToe0, etc...). Expose the transform for one of those cap-like controllers, and you can easily reference it as a the tail-end of the extremity in question.

    That said, this would require modifying the model data if you don't already have these kinds of caps set. As far as I can tell, this is your absolutely only option other than pure mathematical extrapolation (guessing) based on the length of some other bone in your extremity. For instance, saying that the last bone is 60% of the length of the next-to-last bone, and you can calculate the length of THAT bone by comparing the final two transforms you have. Using the final transform's rotation, you can then calculate the "final point" in world space, and use that for your measurement of the total length of the extremity.
     
    Last edited: Jul 28, 2015
  7. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    i've no idea what caps you mean, could you elaborate on that?

    At the moment i'm thinking of just getting my animator to add in some more bones for measuring purpose, but i would prefer not to complicate the model farther if there's any other way
     
  8. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Looking back in 3DS Max, it appears that the "caps" I made actually were just normal bones, but really small. Since I didn't have fingers on my character's hands, I needed a method of controlling the end of shovel-like hands. I did that by making one extra bone sticking out the top beyond the mesh, to serve as a controller. Sorry, I know it wasn't the answer you wanted.