unity3d Overview


Example

Transforms hold the majority of data about an object in unity, including it's parent(s), child(s), position, rotation, and scale. It also has functions to modify each of these properties. Every GameObject has a Transform.

Translating (moving) an object

// Move an object 10 units in the positive x direction
transform.Translate(10, 0, 0);

// translating with a vector3
vector3 distanceToMove = new Vector3(5, 2, 0);
transform.Translate(distanceToMove);

Rotating an object

// Rotate an object 45 degrees about the Y axis
transform.Rotate(0, 45, 0);

// Rotates an object about the axis passing through point (in world coordinates) by angle in degrees
transform.RotateAround(point, axis, angle);
// Rotates on it's place, on the Y axis, with 90 degrees per second
transform.RotateAround(Vector3.zero, Vector3.up, 90 * Time.deltaTime);

// Rotates an object to make it's forward vector point towards the other object
transform.LookAt(otherTransform);
// Rotates an object to make it's forward vector point towards the given position (in world coordinates)
transform.LookAt(new Vector3(10, 5, 0));

More information and examples can be seen at Unity documentation.

Also note that if the game is using rigid bodies, then the transform should not be interacted with directly (unless the rigid body has isKinematic == true). In those case use AddForce or other similar methods to act on the rigid body directly.