In one of the videos of the dead earth game dev series , the author mentions
of calculating a local desired velocity of a
My point of confusion was, wasn't the desired velocity local to begin with? From the docs, it's given that desired velocity is:
The desired velocity of the agent including any potential contribution from avoidance. (Read Only)
since the agent is dynamic shouldn't the velocity already be calculated in the agent's local space, I thought so atleast because it would make sense because most useful case for us is to calculate a certain angle based on the orthogonal vector of one of the axes of the agent's local space and the desired velocity for which desired velocity should be in local space?
And, then he converts the
desiredVelocity to local space of the agent by doing
transform.InverseTransformVector(desiredVelocity). It's using this means that there's an inverse transformation matrix cached by unity. Since, the navAgent is dynamic, it's origin moves about, i.e. the local space moves about as well. So, does that mean the inverse of the transformation matrix from world to local space is calculated for each frame?
So, this I faintly recall is a problem related to change-of-basis of vector spaces? The transformation between these spaces should be guide by a transformation matrices say
M, assuming both these spaces are orthogonal, and the bases for each is of unit length, the transformation composition is typically:
M=TR, where T is a transformation matrix and R is a rotation matrix.
Now, the question is, if (a, b) in w-space is equal to (a, b) in a-space, then T should be an identity matrix, which means no
transform.InverseTransformVector(....) should be required at all, since there's no translation at all, but, if it is required, then what is the translation? And as you demonstrate in your code that it could just be an inverse-rotation, then, why the need to convert it into localspace at all? It could just be the inverse-rotation in world space itself.