I’m new to Unity, and I’m trying to write a script that controls the skeleton of a simple humanoid. I’m trying to dynamically determine the dimensions (length) of each bone of a skeleton, and the coordinates of the joints.
I think I’ve got a pretty good estimation, by getting the difference between Transform.position of the limb, and the Transform.position of the child it is attached to.
Example:
And I’m sure there’s some vector math that can be done with Vector3 objects mb like:
float upper_leg_length = deltaVec.magnitude```
But besides this optimization, is there a better way to determine the dimensions of individual bones?
Best regards,
Mikhail
To my knowledge there isn’t that information automatically available but I might be wrong. Most likely if there’s anything that would allow you to access that data, it would be found on this page:
Is there any reason why you are worried about the optimization? I would imagine that you don’t need to calculate scale of humanoid bones every frame, as the limbs are of same length, so their dimensions don’t change in that sense?
Thank you for your reply, looking through the Scripting API right now, including AnimationModule, so far haven’t found anything better.
With regards to optimization - I’m using Unity for 3D visualization of some kinematics rather than programming a game. I plan to implement muscles as soon as I figure out the skeleton, and muscles have a tendency to change length.
EDIT: I should probably add - Mecanim/Animator might be what I’m looking for, but I haven’t figured out exactly how to attach my model to Mechanim, and until I do, I can’t say for sure that it suits my needs.
EDIT: I still can’t find any way to control the bones and muscles through Mechanim/Animator. Seems like if I link my rig to the animator, then the physics are controlled by Mecanim, and I lose the ability to modify the kinematics and physics the way I want.