CodeBlanks Logo Icon CodeBlanks

Summary - Transform

Reinforce Transform usage with a summary task.

Transform Overview

The Transform component manages an object's position, rotation, and scale. position represents world position, while localPosition represents position relative to the parent. You can use Vector3 to assign new coordinates, Translate for relative movement, and Quaternion to set rotation.

transform.position = new Vector3(3, 0, 2);
transform.Translate(1, 0, 0);
transform.rotation = Quaternion.Euler(0, 90, 0);

Practice Complete the Transform Review Task

Inside the Start method of a Unity C# class, set the object's world position to (2, 0, 3). Then move it one unit along the X axis using Translate and set its rotation to 90 degrees around the Y axis. Finally, print its new world position in the Console window.

Starter code

Player.cs
using UnityEngine;

public class TransformReview : MonoBehaviour
{
    void Start()
    {
        // Set the initial world position.
        // Apply relative movement.
        // Set the rotation.
        // Print the resulting position.
    }
}

Sample solution

Player.cs
using UnityEngine;

public class TransformReview : MonoBehaviour
{
    void Start()
    {
        transform.position = new Vector3(2, 0, 3);
        transform.Translate(1, 0, 0);
        transform.rotation = Quaternion.Euler(0, 90, 0);
        Debug.Log(transform.position);
    }
}

Expected output

(3.00, 0.00, 3.00)

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which property should be used to change an object's position relative to its parent?

  • transform.localPosition Correct answer
  • transform.rotation
  • transform.position
  • transform.Translate

Explanation: localPosition determines the object's position relative to its parent's coordinate system.

2 Complete the Transform Rotation

Question
transform.rotation = Quaternion.Euler(0, ____, 0);
Answer
transform.rotation = Quaternion.Euler(0, 90, 0);

Explanation: Quaternion.Euler sets rotation in degrees. The second parameter represents the Y axis.

3 Review Transform Operations

Term Meaning
transform.position Represents world position
transform.Translate Applies relative movement
Quaternion.Euler Creates a rotation value from angles
transform.localPosition Represents position relative to parent

All lessons in Beginner