Making games

Scenes and objects

A game is made of scenes: a level, a menu, a test room. A scene is a tree of objects, and an object is nothing but a name and a list of components. What an object is (a crate, a light, a door, the player) is entirely which components it carries.

Scenes

File → New Scene (Ctrl+N) starts an empty one, Open Scene (Ctrl+O) opens one, and Save Scene (Ctrl+S) saves it into assets/scenes. Scenes are ordinary assets, so a project can have as many as it needs, and the Assets panel opens one with a double-click.

The scene a game starts in is set in File → Project Settings → General → Startup. A script moves to another with Scene.load(...), or starts the current one over with Scene.restart(); see the Cog API.

Objects

The Scene menu creates objects that already have the components their name says: Cube, Light, Camera, Particles and Canvas. Create Empty makes one with nothing but a transform, which is useful as a folder for other objects or as the start of something built from scratch.

The selected object’s name is at the top of the Inspector; click it to rename the object, or press F2. The eye at the end of a Hierarchy row hides the object: it isn’t drawn, in the editor or in the game, though it still collides and runs its scripts. A hidden object’s eye stays showing, so you can find it again.

Parents and children

Drag an object onto another in the Hierarchy to make it a child. A child moves, turns and scales with its parent: its transform is measured from the parent’s, not from the world’s origin. That is how a car’s wheels follow the car and a gun follows the hand holding it.

The Skyhawk example is a good picture of this. Its Aircraft object holds ControlSurfaces, LandingGear, Propeller, Cockpit and more, and moving Aircraft moves all of them.

The transform

Every object has a Transform, and it can’t be removed. It has three values, each an x, y and z:

PropertyWhat it is
TranslationWhere the object is, in units. One unit is one meter to physics and to the camera.
RotationHow it’s turned, in degrees about x, y and z.
ScaleHow big it is, as a multiple of its natural size. 1, 1, 1 is unscaled.

Y is up. A cube sitting on the ground at the origin has a translation of 0, 0.5, 0.

The three rotation angles are applied Y first, then X, then Z, each about the axes the turn before left behind: turn to face a direction, then tilt up or down, then roll. So Y is always the heading: a camera at -30, 90, 0 faces left and looks 30 degrees down, and changing its Y turns it without tipping it over. Godot uses the same order, and Unity’s comes to the same rotation.

You type the angles, and they stay as you typed them. When something else turns the object (the rotate tool, physics, a script), the Inspector shows angles worked out from where it ended up. The same turn can be written more than one way, so those may not be the numbers you’d have picked: 180, 0, 180 and 0, 180, 0 face the same way.

Scripts read and set an object’s place in the world (self.position, self.rotation, and self.euler_angles in degrees in this same order), and the numbers the Transform holds as self.local_position, self.local_rotation and self.local_euler_angles. For an object with no parent they’re the same. See Working with objects.