- Home /
What is the difference between transform.up and Vector3.up?
I'm assuming transform.up is the direction pointed in by the z-axis of the transform of a game object. But what about Vector3.up? Is Vector3.up the direction pointed in by the world z-axis?
Please someone, help me out.
Thanks, and much love!
How about reading the documentation
Transform.up
The green axis of the transform in world space.
$$anonymous$$anipulate a GameObject’s position on the Y axis (green axis) of the transform in world space. Unlike Vector3.up, Transform.up moves the GameObject while also considering its rotation.
When a GameObject is rotated, the green arrow representing the Y axis of the GameObject also changes direction. Transform.up moves the GameObject in the green arrow’s axis (Y).
Answer by Kishotta · Apr 02, 2018 at 10:12 AM
Vector3.up
refers to "Global up". No matter where you are, how you look at it, Vector3.up
will always be the value <0, 1, 0> (the normalized positive y-axis direction).
transform.up
, on the other hand, changes with respect to the transform in question. If I have the transform of a tree that has fallen on the ground, the tree's "up" direction (toward's the leaves) is no longer "up" in regards to how we might stand on the ground.
If you want to do more reading on the subject, I suggest you do searches for global vs local space vectors.
Thanks @$$anonymous$$ishotta,
That's clear enough, but just to be sure that i understand your explanation. If the tree's transform.up was initially aligned with Vector3.up (the global up), and the tree fell over forward, then would that mean the tree's transform.up (its normalized positive y-axis) is now aligned with the Vector3.forward (the global forward - that is, the global "normalized positive z-axis")?
Sounds right. Its just World vs Local axes.
Okay, thanks for acknowledging that for me.
Correct. Initially, with the tree perfectly "upright", the two up
vectors are identical. When the tree falls though, the tree transform's "up" will drift farther and farther away until it lands on the ground (not necessarily flat, you could use Vector3.Angle (transform.up, Vector3.up)
to get the actual angle difference).
Huge thank you, you've been a great help. Cheers