Thx so much for all replies. Did not expect it. I’m making an inverse kinnematics system, it calculates the rotation it wants to be applied in two steps. In the first step I’m not rotating the object but store the axis i want it to have and the second step looks at these axis and rotates them again. Anyway that part works and here is that code:
r = Quaternion.FromToRotation (BoneVector[n-1, 1],BoneVector[n-1,2]);
forward [n-1, 2] = r*forward [n-1,1];
right [n-1, 2] = r *right[n-1, 1];
up [n-1, 2] = r*up [n-1, 1];
t[n].transform.rotation = Quaternion.LookRotation(forward[n,2],up[n,2]);
BoneVector[i,j] is the vector along the object “i” which could be something else than the objects forward vector. j is 0,1, or 2. a value of 0 means the direction before any rotation, a value of 1 is after tha first rotation and 2 is after the second rotation.
Again, that works but this does not. its not understandable without more code shown, but what i would need to show is like 50 lines:
r = Quaternion.FromToRotation (BoneVector[n-1, 1],BoneVector[n-2,2]);
Boneperp1 [n - 1, 1] = r * Boneperp1 [n - 1, 1];//the perpendicular axis to previous bone direction if that bone had pointed straight in the same direction as the bone before that.
Boneperp2 [n - 1, 1] = r * Boneperp2 [n - 1, 1];
What i want to do is rotate a bone to face the direction of its parent. And in doing so i want to check what my up vector became. I’m rotating the bone in various ways around the x and y axis(if z is along the bone), but never around the z axis. So if the bones bonevector started pointing along the parents bonevector but then after some rotations did not, but I rotated it back, the right and up axis would be the same as they were before the rotations. This may be my misstake though.
The thing is that i pretty much want to use the parents right and up Vectors and i have those. But I’m allowing the user to have any forward direction of the bone so it may be that its the -y and z that would point in the x and y direction of this child bone after rotating it back. And i’m allowing the bones to at start not being alligned with each other.