- Home /
how to apply overall rotation to collection of rotated objects
The question is bad, but I can't think of how to put it succinctly.
I have an object composed of several cylinders. Each cylinder is a body part, and the position information from Kinect is used to position and rotate each cylinder to mimic a human body. For example, the forearm is put in place by:
bone.transform.position = ( wristposition + elbowposition )/2f;
bone.transform.up = (wristposition - elbowposition );
That works well enough to be convincing. Now I would like to rotate the entire bone pile to match the world rotation of the parent body. Everything I have tried so far has been no good. Either the bone pile sternly faces straight down the Z-axis, or the bones rotate around their center in a most non-human way.
Any ideas?
Can these not be parented to a root object? You'd have to set their localPosition and localRotation, etc, ins$$anonymous$$d of simply "position" and "rotation", but it would allow you to drive root motion by whatever means you like. Sounds really cool btw, I'm jealous. :)
The bone.transform.up does not seem to have a "local rotation" -- looks like it uses only world rotation.
Here is a vastly simplified version:
Create a cube of one unit size.
As a child of the cube, create a cylinder that is size ( 0.2, 2, 0.2 )
Attach a script to the cube with void Update () {transform.Rotate (Vector3.up * 30f * Time.deltaTime);}
Attach a script to the rod with void Update () { transform.up = new Vector3 (2, 2, 2);}
Run it, and you will see that the cube rotates but the rod does not. Somehow I need to change the direction to which the rod points based on the rotation of the cube. Right now I'm going down the path of instantiating small balls at the location of each joint, then rotating that. Then take the world coords, and use them to point the bones. Very clunky and stupid wasteful, but it seems to work.
What I want is to eli$$anonymous$$ate the unnecessary step of creating joint balls, and just do the math I need.