- Home /
I want a better explination than the one in unitys tutorial
So I'm using the scripting method transform.forward with a transform and I'm trying to figure out how it works. Unity explains it as "The blue axis of the transform in world space.". Can somebody explain what this means. I'm using it for a 2d platforming shooter and I'm using a gameobject called gun end attached to the end of the gun and it turns left and right would this work for me to add force in the direction I want. Although main thing is just explaining using transform.forward please help.
You know that thing in the scene view that has those red/yellow ,green and blue arrows? Those arrows stand for the x.y.z postition of your object.
Answer by Vice_Versa · Aug 11, 2015 at 11:48 PM
x(red arrow) goes sideways, y(green arrow) goes up and down, z(blue arrow) goes forward and backward. As for the "transform.forward" method, transform means an objects location, rotation, and scale. Transform refers to all of those but is also sort of another way to reference a gameObject. transform.forward means get the forward direction (z axis) of your transform(gameobject). if your making a 2d platformer game, im assuming transform.right is probably what you want to use
Answer by Eno-Khaon · Aug 12, 2015 at 12:29 AM
When working with these directions and orientations, there are two aspects to keep in mind: Global and Local orientations.
When talking about an object's Global (or "World") position or rotation or scale alike, that is the final, resulting orientation of an object. As far as position (or "translation") is concerned, as has been described, the three-dimensional status is represented with a horizontal red arrow (X-axis), a vertical green arrow (Y-axis), and a horizontal blue arrow crossing them (Z-axis).
The Z-axis is considered to be pointing "forward", therefore the X-axis points to the right and the Y-axis points up. These correspond with Vector3.forward, Vector3.right, and Vector3.up respectively.
Now, this is DIFFERENT than transform.forward, right, and up.
An object's local orientations are very important, especially when you have multiple objects with a parent/child relationship. This is what you see when you drag an object onto another in your hierarchy window in Unity.
Let's say you have an object which you shrink down to 1/100 of its normal size, so it's ridiculously tiny. Then, you make another one its child. That child will appear to be normal size relative to the world. However, it will actually be 100 times enlarged, because that is the object's relative scale to its parent.
Now, in this case, there's NOT a parent/child relationship, so why does the local rotation matter? Well, it's actually very simple. Face North. Then, turn to your right. Now, you're facing East. Either way, you're looking forward, but to the world, North won't change.
The same holds true for global and local rotation. You can think of the global Z-axis as a line running north and south. This represents north as "Vector3.forward". However, the direction anyone or anything is facing is their own. This is represented by "transform.forward" instead.
You mention you're working on a 2D game, which really doesn't change very much. The X-axis runs from left to right. The Y-axis runs from bottom to top. However, without depth, there is no Z-axis to worry about. Instead, if your character naturally faces to the right (in other words, your character faces right with 0-degrees of rotation applied), then transform.right will act as your character's relative "forward" direction. If the game is, instead, a vertical shooter or a top-down racing game, those often have a character facing upwards by default. It's just a matter of knowing where to start.
Your answer
![](https://koobas.hobune.stream/wayback/20220611235439im_/https://answers.unity.com/themes/thub/images/avi.jpg)