difference between transform.forward and vector3.forward

Hello,
I’m learning unity C# and i’m confused between transform.forward and vector3.forward, please teach the difference between these two, here is the code i’m trying and they both giving different results(in this case i wanted vector3.forward)

transform.position = Pivot.position + transform.rotation * Vector3.forward * -Distance;
transform.position = Pivot.position + transform.rotation * transform.forward * -Distance;

Vector3.forward is the unit vector defined by (0, 0, 1)

transform.forward is the forward direction of the object in the world space. It’s the direction your object is “looking at”, and depends on the various rotation you made on the object.

Supposing you instantiate a simple cube at the root of the scene, its forward vector will be (0, 0, 1). Now, if you rotate the object 90° clockwise on the Y axis, its new forward vector will be (1, 0, 0)

But in your code, you have a specific case :

transform.rotation * Vector3.forward makes the product of a rotation quaternion with the Vector.forward. This operation will result in a direction vector equals to transform.forward

Thus, I don’t think transform.rotation * transform.forward is what you really want to do.

This post is a couple of years old so not sure if anyone will see this, but I have a follow-up question (forgive me if this should go in a separate post):

I have a script attached to an object to make it rotate around its local Z axis like so:
transform.Rotate(Vector3.forward, rotationAmount);

The funny thing is this is actually getting me the desired result, just not sure why:

The object this script is attached to, is the child of a parent object that is also being rotated.

Now, when I rotate the parent object, the child object’s rotate script (using Vector3.forward) still seems to rotate the child object around its own LOCAL forward axis (which is actually the desired effect), whereas using transform.forward produces a strange result.

My question, I guess: what’s causing this to be the case? Is this something to do with transformation order, or the child object inheriting the parent object’s transform info?

I’m actually getting my desired result so I guess it’s fine, just kinda baffled as to WHY :slight_smile: