- Home /
What is the difference between TransformDirection, TransformVector and TransformPoint since they all accept and return a Vector3 value.
I am a little confused about the these three functions as they accept and return a same kind of variable that is a Vector3. I would really like some passerby to leave me a few words of clarification on this topic. Thanks.
Answer by meat5000 · Mar 28, 2017 at 04:00 PM
Erm, yes, the Vector3 system in Unity (or in Mathematics for that matter) requires a little imagination.
Remember that a Vector consists of a Direction and a Distance.
Remember that Vectors are totally Commutable (They can be moved around and the same vectoral representation holds true).
In Mathematics we put a line over the Algebraic term to indicate its a Vector. In Unity we need to tell the compiler HOW to interpret the Vectoral information in the same way we tell it how to interpret Variables (int, float etc).
(1.0, 1.0, 1.0) is a point in space. Using a little imagination we can also consider that it can also represent a Vector IF WE ASSUME that the start of the Vector is at (0,0,0). This is the information that is missing and why it confuses you. Back to remembering that Vectors are commutable and suddenly you can see that this (1.0, 1.0, 1.0) can represent a vector of that direction and length anywhere in space. It still looks the same as a point in space but WE KNOW ITS NOT and we need to tell Unity how WE see it and would like to use it.
I presume TransformDirection returns a Unit Vector indicating a direction with no distance.
I presume TransformPoint returns a point in space.
I presume TransformVector returns a Vector which contains Direction and Distance provided you use the assumption that 0,0,0 is the starting point (dont worry its commutable).
This infomation will all look the same but you know its not.
Is any of this making sense? Feel like I'm rambling.
Hey, thanks a lot.You explained it really well.All of a sudden my doubts are clear.
Just to add to this,
TransformDirection doesn't return a unit vector, it uses the inverse of the object's rotation to change a vector's direction into world space coordinates, keeping the length of the vector.
TransformVector does the same as TransformDirection but also changes the length of the vector depending on the scale (size) of the object.
TransformDirection is used to change the direction of local vectors to world vectors. Say for example, you had a force that you wanted to apply to an object and you always wanted the force to be in the object's upwards direction you would use
transform.TransformDirection( new Vector3(0, 1, 0);
to get the force in world coordinates and then use AddForce. This is just an example and Unity has AddRelativeForce which will do this for you.
I have never found a need to use TransformVector as scaling up vectors when transfor$$anonymous$$g them has never been something I've had to do.
Your answer
Follow this Question
Related Questions
transform.position is giving me local space 1 Answer
Add force forward to a ball using local coordinates doesn't work as I wanted 1 Answer
How do i move an object relative to another objects axis. 2 Answers
Instantiate prefab as child at a transform? (Javascript/Uniyscript) 2 Answers
Move camera along 2 axes in WorldSpace 2 Answers