Unity - Scripting API: Transform.forward

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

Returns a normalized vector representing the blue axis of the transform in world space.

Unlike Vector3.forward, which is a constant direction in world space, Transform.forward is the local forward direction for this GameObject. Rotating this GameObject will change the Transform.forward direction.

The example below shows how to manipulate a GameObject’s position along the Z axis (blue axis) of the transform in world space.

Another example:

using UnityEngine;

// Computes the angle between the direction of the target from this object and this object's viewing direction (forward).

public class Example : MonoBehaviour { public float angleBetween = 0.0f; public Transform target;

void Update() { Vector3 targetDir = target.position - transform.position; angleBetween = Vector3.Angle(transform.forward, targetDir); } }