I was wondering how Unity calculates new positions of a child object when rotating the parent object.
It happens in the game, but I want to do it from scratch.
This is my Attempt:
Vector3 parentPos; //global position parent
Quaternion parentRot; //global rotation parent
Vector3 childPos; //local position child
m = Matrix4x4.TRS(parentPos, parentRot, Vector3.one);
Vector3 newPosition = m.MultiplyPoint(childPos);
Explaination:
The parent object has position and a rotation, with MultiplyPoint(Vector3) it should give the new point in global space. Unfortunately is gives slightly wrong values.
Solved it - for everyone wondering: “A feature of quaternions is that multiplication of two quaternions is noncommutative” - Wikipedia
The above shown approach is correct, but i mistakenly multiplicated childObjectRotation * parentObjectRotation, not vice versa.