- Home /
InverseTransformDirection and Velocity
I am trying to make a flight simulator and to add lift and drag properly I need the angle of attack of the airplane which is defied as : Angle between the chord line of the wing and the velocity of the aircraft .
At first I thought this is pretty straightforward , just the angle between forward vector and the velocity vector, this is how I defined my AngleOfAttack
aoa = Vector3.Angle(transform.forward , rb.velocity)
then I found somewhere that this method is wrong, this is what the person wrote :
Vector3.forward and rb.velocity are both in world-space. AoA is the angle between the local chord-line of your wing and the aircraft's velocity.
Vector3.Angle will return an unsigned angle. AoA must work in both positive and negative directions otherwise negative pitch and inverted flight would not be possible.
and to provide the solution , this is what he wrote :
Solution: Move rb.velocity to local-space and solve for AoA with trigonometry.
// *flip sign(s) if necessary*
var localVelocity = transform.InverseTransformDirection(rb.velocity);
var angleOfAttack = Mathf.Atan2(-localVelocity.y, localVelocity.z);
This is what I don't understand , If I'm measuring the velocity of an object , relative to its own space it should be always zero . Right ? How does InverseTransformDirection work here .
Answer by Namey5 · Jul 23, 2019 at 05:44 AM
In this case, space refers to the origin and its relationship with positions and directions. Transforming a world space vector to a local space vector simply changes it's relationship with the world, not the actual values inherent within the vector. In world space, the origin is the centre of the world with the x, y and z axis' fixed. In local space however, the origin is relative to the object's position, and the x, y and z axis' are relative to the object's rotation. As such, all this code segment does is transform the velocity such that it is relative to where the aircraft is looking so that we can find the unsigned angle easier.
Your answer
![](https://koobas.hobune.stream/wayback/20220612205330im_/https://answers.unity.com/themes/thub/images/avi.jpg)