Manipulating a Running Scene

Overview

Loading a scene made in the scene editor draws it, but intentionally does nothing else. The items in view match the scene editor's camera, and the graphics match as well. To move a character, add game logic or respond to the player takes code. This page shows how a program finds an item from the scene by its name, and then moves it with the keyboard, in 2D and in 3D: first by hand, so you can see how movement works, and then the easy way, with a ready-made movement controller and a camera that follows.

Goals

By the end of this lesson, you can

  • Find an item from a loaded scene with FindItem2DByName or FindItem3DByName.
  • Check whether an item was found before using it.
  • Move a found item when the player presses keys, by hand.
  • Move a found item with a movement controller, and make the camera follow it.

Warm up

In a crowded room, how do you get one particular person's attention? Now imagine a game with a hundred items in its scene. How could a program pick out the one it wants to move?

Vocabulary

You will be learning about the following vocabulary words:

Vocabulary
TermDefinition
Item nameThe name given to an item in the scene editor. It is shown in the scene tree and can be changed in the Properties panel. Code uses it to find the item.
undefinedA value meaning "nothing here". A find action gives back undefined when no item has the name it was asked for.
ListenerAn object that is told when something happens, such as a key being pressed.
Key codeA number that says which key was pressed. KeyboardEvent has a name for each one, such as LEFT or PAGE_UP.
BehaviorCode that can be added to an item to make it do something every frame, such as move when keys are pressed.
Movement controllerA ready-made behavior that moves an item with the keyboard. Quorum has MovementBehavior2D and MovementBehavior3D.

New Code to Learn

You will be using the following new pieces of code:

New Code to Learn
Quorum CodeCode ExampleExplanation
FindItem2DByName(text name)Item2D player = FindItem2DByName("1: Boy")Gives back the first 2D item with this name, or undefined if there is none.
FindItem3DByName(text name)Item3D player = FindItem3DByName("Cube")Gives back the first 3D item with this name, or undefined if there is none.
AddKeyboardListener(KeyboardListener listener)AddKeyboardListener(me)Asks the game to tell this program about key presses, by calling its PressedKey action.
PressedKey(KeyboardEvent event)action PressedKey(KeyboardEvent event)Runs each time a key is pressed. The event says which key.
keyCodeif event:keyCode = event:LEFTChecks which key was pressed.
Move(number x, number y)player:Move(-20, 0)Moves a 2D item by an amount: here 20 pixels to the left.
Move(number x, number y, number z)player:Move(0, 0, 1)Moves a 3D item by an amount: here 1 unit forward, along z.
outputoutput "Found it"Writes text in Quorum Studio's output window, which is handy for checking what a program is doing.
MovementBehavior3DMovementBehavior3D movementA movement controller for a 3D item: W and S move it, A and D turn it, Space jumps.
MovementBehavior2DMovementBehavior2D movementA movement controller for a 2D item: the arrow keys, or W, A, S and D, move it.
AddBehavior(Behavior behavior)player:AddBehavior(movement)Gives a behavior to an item, which then runs it every frame.
Follow(item)GetCamera3D():Follow(player)Makes a camera follow an item: in 3D from behind and above, in 2D by keeping it in the middle.
SetSpeed(number speed)movement:SetSpeed(6)Sets how fast a controller moves its item: meters per second in 3D, pixels per second in 2D.

CSTA Standards

For teachers · 2026 CSTA K–12 Computer Science Standards

HS-PRO-PD-13

High School · Programming

Use documentation, libraries, application programming interfaces (APIs), and other tools in program development.

Also in 5 other lessons

S1-GMD-DD-03

Specialty I · Game Development

Develop an interactive experience to support gameplay.

Also in 1 other lesson

HS-PRO-RD-17

High School · Programming

Analyze how a segment of code works, including the role of parameters, return values, and data structures.

Also in 6 other lessons

Every standard, and the lessons that cover it

Explore

Scene Manipulation

Because making an application do what is wanted in code is a big topic, this page doesn't explain how everything works. It focuses on getting items from a scene so they can be moved or used in other ways. For more on coding games, see the games tutorials, such as Keyboard Events and Getting Started with Games.

The programs below start from the runner on Running a Scene and add a few lines.

Moving a Character in 2D

In a 2D scene, place the boy from the palette: Characters 2D, then Boy, then 1: Boy. The editor names him 1: Boy, the name from the palette, and announces "Placed 1: Boy". Save the scene, then use this program:

use Libraries.Game.Game
use Libraries.Interface.Item2D
use Libraries.Interface.Events.KeyboardListener
use Libraries.Interface.Events.KeyboardEvent

class Main is Game, KeyboardListener
    Item2D player = undefined

    action Main
        StartGame()
    end

    action CreateGame
        LoadScene("Scenes/Scene.qs")

        player = FindItem2DByName("1: Boy")
        if player = undefined
            output "The scene has no item named 1: Boy."
        else
            AddKeyboardListener(me)
            output "Found 1: Boy. The arrow keys move him."
        end
    end

    action Update(number seconds)
    end

    action PressedKey(KeyboardEvent event)
        // How far, in pixels, one key press moves the boy.
        number amount = 20

        if event:keyCode = event:LEFT
            player:Move(-amount, 0)
        elseif event:keyCode = event:RIGHT
            player:Move(amount, 0)
        elseif event:keyCode = event:UP
            player:Move(0, amount)
        elseif event:keyCode = event:DOWN
            player:Move(0, -amount)
        end
    end
end

The most important line is the one that finds the boy: player = FindItem2DByName("1: Boy"). When an item has a name in the scene, this action finds it in the running game.

In 2D, x grows to the right and y grows upward, so the up arrow adds to y.

Moving an Item in 3D

In a 3D scene, place a Cube from the Basic 3D section of the palette. The first cube is named Cube. Save the scene, then use this program:

use Libraries.Game.Game
use Libraries.Interface.Item3D
use Libraries.Interface.Events.KeyboardListener
use Libraries.Interface.Events.KeyboardEvent

class Main is Game, KeyboardListener
    Item3D player = undefined

    action Main
        UseVulkan(true)
        StartGame()
    end

    action CreateGame
        LoadScene("Scenes/Scene.qs")

        player = FindItem3DByName("Cube")
        if player = undefined
            output "The scene has no item named Cube."
        else
            AddKeyboardListener(me)
            output "Found Cube. The arrow keys move it. Page Up and Page Down raise and lower it."
        end
    end

    action Update(number seconds)
    end

    action PressedKey(KeyboardEvent event)
        // How far, in units, one key press moves the cube. A cube from the
        // palette is 1 unit wide.
        number amount = 1

        if event:keyCode = event:LEFT
            player:Move(-amount, 0, 0)
        elseif event:keyCode = event:RIGHT
            player:Move(amount, 0, 0)
        elseif event:keyCode = event:UP
            player:Move(0, 0, amount)
        elseif event:keyCode = event:DOWN
            player:Move(0, 0, -amount)
        elseif event:keyCode = event:PAGE_UP
            player:Move(0, amount, 0)
        elseif event:keyCode = event:PAGE_DOWN
            player:Move(0, -amount, 0)
        end
    end
end

Here the line that matters is player = FindItem3DByName("Cube"). In 3D, y is up, so the arrows move the cube along the ground (x and z), and Page Up and Page Down move it up and down. With the camera where a new scene puts it, the up arrow moves the cube away from the camera.

The Easy Way: Movement Controllers

Writing a PressedKey action for every key works, but most games need the same things: move smoothly while a key is held, turn, jump, and bump into walls instead of passing through them. Quorum has ready-made movement controllers that do all of this. A controller is a behavior: code you give to an item, which then runs on every frame. To use one, make it, give it to the item with AddBehavior, and run.

Here is the 3D cube from above, moved by a controller, with the camera following it:

use Libraries.Game.Game
use Libraries.Interface.Item3D
use Libraries.Interface.Behaviors.Games.MovementBehavior3D

class Main is Game
    action Main
        UseVulkan(true)
        StartGame()
    end

    action CreateGame
        LoadScene("Scenes/Scene.qs")

        Item3D player = FindItem3DByName("Cube")
        if player = undefined
            output "The scene has no item named Cube."
        else
            MovementBehavior3D movement
            player:AddBehavior(movement)
            GetCamera3D():Follow(player)
            output "W and S move the cube. A and D turn it."
        end
    end

    action Update(number seconds)
    end
end

The three lines that matter are MovementBehavior3D movement, player:AddBehavior(movement) and GetCamera3D():Follow(player). Hold W or the up arrow and the cube moves forward, the way it faces; A and D, or the left and right arrows, turn it; S or the down arrow backs it up. The camera follows from behind and above, turning as the cube turns.

The 2D version works the same way. Here is the boy, moved by a 2D controller, with the camera keeping him in the middle of the screen:

use Libraries.Game.Game
use Libraries.Interface.Item2D
use Libraries.Interface.Behaviors.Games.MovementBehavior2D

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        LoadScene("Scenes/Scene.qs")

        Item2D player = FindItem2DByName("1: Boy")
        if player = undefined
            output "The scene has no item named 1: Boy."
        else
            MovementBehavior2D movement
            player:AddBehavior(movement)
            GetCamera2D():Follow(player)
            output "The arrow keys move the boy."
        end
    end

    action Update(number seconds)
    end
end

The arrow keys, or W, A, S and D, move the boy up, down, left and right.

Changing How It Feels

Each controller has settings you can change with one line, after making it:

Movement controller settings
SettingExampleWhat it does
Speedmovement:SetSpeed(6)How fast the item moves: meters per second in 3D (4 to start), pixels per second in 2D (200 to start).
Turn speed (3D)movement:SetTurnSpeed(180)How fast the item turns, in degrees per second (120 to start).
Jump heightmovement:SetJumpHeight(2)How high the item jumps when Space is pressed: meters in 3D, pixels in 2D.
Accelerationmovement:SetAcceleration(4)How quickly the item speeds up and slows down. 0, the start, means at once.
Mode (3D)movement:SetMode(movement:CAMERA_RELATIVE)TURN_AND_MOVE turns with left and right. CAMERA_RELATIVE moves relative to the camera. FLY adds E and Q for up and down.
Mode (2D)movement:SetMode(movement:SIDE_VIEW)TOP_DOWN moves in every direction. SIDE_VIEW moves left and right and jumps, like a platform game.
Keysmovement:SetJumpKey(keys:J)Changes which key does what. Each command can also have extra keys added.

Controllers and Physics

A controller looks at the item's physics settings in the Properties panel and moves it the right way:

  • No physics: the item moves straight through anything in its way.
  • Responsive: the item bumps into walls, falls with gravity, and can jump when it's standing on something. Turn on physics in the program with EnablePhysics3D(true) and SetGravity3D(0, -10, 0) after LoadScene, as on Running a Scene.
  • Nonresponsive: the item pushes other things out of its way, but nothing pushes it back.
  • Unmovable: the item can't move. The controller says so in the output, so you know to change it.

A 3D controller also keeps its item upright, so a character doesn't tip over when it bumps into something. Forward is the way the item faces. If a model walks sideways or backward, its front isn't facing the way Quorum expects; turn it in the scene editor so it faces along z.

Names, and When Nothing Is Found

These actions give access to items created and loaded in a scene, so they can be moved by keyboard, mouse or whatever makes sense for the game being made.

  • Names are exact. 1: Boy and 1: boy are different names. The scene tree shows each item's name, and the Name field in the Properties panel (Cmd+P on Mac, Ctrl+P on Windows) changes it. A short, clear name, like Player, makes code easier to read.
  • Copies get numbers. The editor names a second cube Cube 1, a third Cube 2, and so on. Items can still end up with the same name, for example by renaming them. Then the action gives back the first item it finds with that name, not all of them. To reach every item, a program can go through a layer's items one by one, with GetCurrentLayer3D():GetIterator().
  • Nothing found means undefined. If no item has the name, the action gives back undefined. Using an undefined item stops the program with an error, which is why both programs check first and write out what happened.

Terrain Is an Item Too

A terrain placed in a 3D scene is also an item, named Terrain (then Terrain 1, and so on), so FindItem3DByName("Terrain") finds it. The terrain pages start with Terrain in a Scene; Terrain in a Game shows how to find the ground and ask how high it is.

Engage

In this activity, you and a partner connect a scene built in the editor to code that controls it, first by hand and then with a movement controller. The goal is to find items by their names in code, move them, and then tune a controller until it feels right. Partner A builds a small 3D obstacle course on a flat floor: a few walls to steer around, a ramp, and a block to jump onto, with a cube named Player at the start and a sphere named Goal at the end. Give the floor, walls and ramp Physics Enabled and set them to Unmovable, and give the player Physics Enabled and set it to Responsive. Partner A tells Partner B only the names, not where things are.

Partner B writes a program that loads the scene, turns on physics and gravity, finds Player and Goal by name, gives the player a MovementBehavior3D, and makes the camera follow it. When Space is pressed, the program should also output how far the player is from the goal. Then take turns running the course, and tune the controller: try at least three changes, such as the speed, the jump height and the acceleration, and for each one write down the setting, its value, and how the course felt afterwards. Finally, try a name with a spelling mistake, such as Playr: what happens, and what appears in the output window? Swap roles with a new course.

Wrap up

Naming items in the scene editor is a promise to the code: the code finds items by those names. Once found, an item can be moved by hand, one key at a time, or handed a controller that does the work every frame. What could go wrong if someone renames an item after the code is written? How would the output lines in these programs help find the problem?