Animating bone programmatically using bone edges as coordinates

Hi :slight_smile:

I would like to know how to animate a bone scripting. I know that I can use them as transforms, manipulating its position and rotation, and that is fine… but as far as I understand, the concept of bone is composed by two points: the origin and the end of the bome.

Through the transform, I can set the position of the first point, but how could I set the position of the end point of the bone programmatically? I want to do it by using position since it is much easier for me than doing it with rotations and scaling the bone if the second point is further (the bone length must change).

In other words, I would like to move the bone according to the position of two points (start and end) or a Vector3 for its length and direction and another one for its origin.

The concept is something like this:

Vector3 start, end;
Transform bone;
bone.position = start;
bone.end.position = end; //this will not work, obviously, but Im looking for something similar

Thanks a lot in advance :slight_smile:

Maybe the code here can help you:

http://forum.unity3d.com/threads/163693-Problem-with-Raycast-and-colliders-on-skeleton

I’m using LookAt to point the bone to a given position in space. There is a link to the project in case you want to try it.

Thank you marcoantap, however with LookAt I can only set the rotation of the bone, i would like to set the end position of the bone, since the length in my project can change.

imagine I have two points :

Vector3 p1 = new Vector(0,1,0);
Vector3 p2 = new Vector(1,2,2);

now i want my bone go from p1 to p2.