Transform
Transform is the required Component on every GameObject — it owns Position, Rotation, and Scale, and defines the object's place in the Scene hierarchy.
Imagine...
Transform is like an object's address card and ID. It records where I am (Position), which way I face (Rotation), and how big I am (Scale). Without a Transform, Unity has no idea where to draw that object on screen.
The concept in detail
Transform stores data in two coordinate spaces: World Space
(absolute from the Scene origin) and Local Space (relative to
the Parent). transform.position is World; transform.localPosition is Local.
Rotation is stored internally as a Quaternion — that avoids
gimbal lock. You usually work through transform.eulerAngles (x, y, z degrees). To rotate
smoothly, use Quaternion.Slerp() or transform.Rotate().
On performance: moving a physics object (Rigidbody) by assigning
transform.position directly skips the Physics Engine and can tunnel through walls.
Use Rigidbody.MovePosition() or AddForce() instead.
World vs Local Space
Position
Vector3(x, y, z)
Rotation
Quaternion / euler
Scale
Vector3(1, 1, 1)
Hands-on steps
Move from code
transform.Translate() or assign transform.position = new Vector3(...)
Rotate smoothly
transform.Rotate(Vector3.up * speed * Time.deltaTime)
Interpolate position (Lerp)
Vector3.Lerp(from, to, t) or Vector3.MoveTowards()
Look at a target
transform.LookAt(target) or use Quaternion.LookRotation()
Interactive simulator
Drag the sliders to change Position, Rotation, and Scale — watch the canvas update live.
Inspector
🟢 Green arrow = Forward
🔴 Red arrow = Right
🟡 Yellow dot = origin (0,0,0)
Code example
Basicusing UnityEngine;
public class TransformBasics : MonoBehaviour
{
[SerializeField] private float moveSpeed = 5f;
[SerializeField] private float rotateSpeed = 90f; // degrees per second
void Start()
{
// Set absolute World Space position
transform.position = new Vector3(0f, 1f, 0f);
// Rotate 45° around the Y axis
transform.eulerAngles = new Vector3(0f, 45f, 0f);
transform.localScale = Vector3.one; // (1,1,1) = original size
}
void Update()
{
// Move forward — multiply by Time.deltaTime so speed is FPS-independent
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
// Spin continuously around Y
transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
}
}Code example
Advancedusing UnityEngine;
public class TransformAdvanced : MonoBehaviour
{
[SerializeField] private Transform target;
[SerializeField] private float followSpeed = 3f;
[SerializeField] private float rotateSpeed = 5f;
void Update()
{
if (target == null) return;
// Smoothly approach the target without overshooting
transform.position = Vector3.MoveTowards(
transform.position,
target.position,
followSpeed * Time.deltaTime
);
// Smoothly look at the target with Slerp
Vector3 dir = (target.position - transform.position).normalized;
if (dir != Vector3.zero)
{
Quaternion lookRot = Quaternion.LookRotation(dir);
transform.rotation = Quaternion.Slerp(
transform.rotation, lookRot,
rotateSpeed * Time.deltaTime
);
}
// Convert World Position → this object's Local Space
Vector3 localPos = transform.InverseTransformPoint(target.position);
// localPos.x > 0: the target is to the right
}
}📌 Quick recap
- ▸Transform is required — you cannot remove it from any GameObject
- ▸
.position= World,.localPosition= Local - ▸Rotation is stored as a Quaternion; you usually edit
.eulerAngles - ▸Always ×
Time.deltaTimeso movement is FPS-independent
⚠️ Common mistakes
❌ Forgetting to multiply by Time.deltaTime
120 FPS moves twice as fast as 60 FPS
✅ Always × Time.deltaTime inside Update()
❌ Using transform.position on an object with a Rigidbody
Skips physics — tunneling through walls and bad collisions
✅ Use Rigidbody.MovePosition() or AddForce()