0

in unity when you parent an object or transform with another object, all transform(position, rotation, scale) are calculated depending on that parent object. sometimes we need to know about the local data of that transform and sometimes we need to know that data based on the world axis.

I need to know how that is implemented in math and vector functions.

virtouso
  • 2,608
  • 6
  • 41
  • 62

2 Answers2

2

Parenting an object essentially means that the object's transform now is relative to the parent's instead of the world's. If the parent object is a body for example and the child object is the arm, then the body's position in the world is defined by its bodyTransform and is relative to the world coordinates but the armTransform is relative to the body's space, which I believe is done via a change of basis on the arm object where the new basis is the body's local basis. This means that you can individually change the arm's position by changing its transform relative to the body (which is what you care about) but if the whole body moves, the arm moves with it since its armToWorld transform already contains the bodyTransform inside.

PentaKon
  • 348
  • 1
  • 9
1

You don't really need to know how that is implemented in math and vector functions. Not having to bother with stuff like that is one of the reasons why you are using a game engine in the first place :) But if you want to know because it interests you:

Internally, Unity implements the whole data of the Transform component with a transformation matrix. A transformation matrix is a collection of 4x4 floating-point values. Encoded in these values is the translation, rotation and scale (and technically also skew, but that's rarely used in 3d graphics).

There is a way to multiply a point (represented as a Vector) with a projection matrix which results in a new point with the rotation, translation and scale applied to it. You can also multiply two projection matrices with each other to get a single new 4x4 matrix which applies the transformations of both matrices one after another. This is how the matrices of transforms in a parent hierarchy are calculated. Unity actually exposes that matrix of a transform and its parent transforms through the property localToWorldMatrix.

OK, but how exactly does that multiplication of a vector with a matrix or a matrix with a matrix work? Lots of people have already written lots of explanations for that which are far better than I could write.

Philipp
  • 119,250
  • 27
  • 256
  • 336