With a Game Controls event, you can create interactive experiences, where you control a character (that’s what we call the controlled object), by walking or flying around your scenes.
Navigate your scene and control your character with key inputs, joysticks and buttons on mobile, gravity, and collision detection.
There are many different options to customize it to the type of experience you decide to build.
Test the gameplay 🎮👇
Before moving on with the documentation, why not give the game controls a quick test below?
W S A D keys to move the character,
SPACE to jump, and
↑↓←→ keys to move the camera.
Game Controls Video Tutorial
If you prefer to follow along with a video, we’ve made this tutorial where we go through all the details of a Game Controls event.
Adding a Game Controls Event
Here's how to add a Game Controls event to an object in your scene:
- Select the object that you want to control.
- On the Events panel, add a new event and select
Game Controlsfrom the dropdown menu.
- Open the Game Controls event and tweak the settings to your liking.
Adjusting Character Orientation
If your character is composed of grouped objects and you notice it is moving backwards, you’ll need to make sure it is facing towards the -Z direction.
To fix this you’ll need to select all the objects inside your main group and rotate them to face the -Z direction.
This usually means rotating all the objects inside your character group by 180º degrees.
Understanding the Game Controls Settings
Let's now dive deep into all the settings that can be found inside the Game Controls event, so you can adjust them to properly match the experience you’re building.
In Movement, you can define how your character will be moving around your scene.
Walk - is used for experiences where you move on surfaces.
Fly - is used for experiences where you fly around your scene.
When turned on, the character rotates automatically based on the direction you’re moving in.
Control the speed of position and rotation.
Control the acceleration at the Start and deceleration at the End of position and rotation.
To create unique game mechanics controls can be adjusted.
Desktop Controls is where we can define what keys are going to be used to control our character and what each of them does.
Define how you can rotate the camera. Either by using the Mouse, the Arrow keys, or both.
Once you select a key, you can either press another key to assign it or change the action of that key on the dropdown below.
If you’ve made too many changes, the reset button (on the top right) will let you reset to the default keys.
Here’s a list of all the behaviors and their default keys:
Move Forward (-Z)
Move Back (+Z)
Move Left (-X)
Move Right (+X)
Rotate Up (+X)
Rotate Down (-X)
Rotate Left (+Y)
Rotate Right (-Y)
Move Up (+Y)
Move Down (-Y)
Multiple Game Controls Events
If you have multiple Game Controls events in your scene, only one of them will be the one where you can define the desktop and mobile controls.
So on every new Game Controls event, you create, you’ll see this warning, letting you know that the event you’re editing is not the main Game Controls event.
But you can always press the button below to make it the main one and edit the controls from there.
Touch Controls lets you define the controls of your experience on touch-based devices like phones and tablets.
Define how you can rotate the camera. Either by dragging on the screen or by using a joystick.
Joysticks and Buttons Position
Choose where to position the joysticks and buttons for Move, Rotate (only visible if Rotate By is set to Joystick), and Jump.
The representation you see is how they will be positioned on the device’s screen.
Offset - The space the control has from the screen edge.
Button Size - The size of each control.
Visibility - Defines if the selected control is always visible or becomes visible when interacted with.
With collision, we can define how our character will collide with everything in our scene.
Make changes to the collider on your character and tweak settings like Gravity, Jump Power, and the Reset Position.
Define the boundaries of your character by choosing a collider like a Capsule or a Sphere, and match it perfectly by changing its size, position and rotation.
Control how your character jumps and falls. As you make the value closer to 0, the character will float more.
Define how high your character will jump.
Reset Y Position
Define the value on the Y axis where if the character reaches it, the scene will reset.
This is useful for scenes with platforms which the character can fall from.
If you need a camera to be following your character, this is where you can define which one will be used for it.
To create a new camera, you can do so from the “+” icon on the toolbar and selecting Camera, or from the Camera Panel and then pressing “Add new camera” from the dropdown.
Make sure to position the camera in the position you want the experience to be viewed by everyone in the final result.
Select the camera that is going to be following your character.
Normal - When moving the character the camera will follow it by moving forward, backwards, or pan to the sides.
Angle - When moving the character the camera will follow it by moving but also rotate at an angle behind the character.
Up/Down & Left/Right
With the directions Up, Down, Left, and Right, you can decide how the user can control the camera.
You can either allow the user to move it in those directions, disable it, or define limits by using angle values.
Remember that the camera used to follow the character should also be the camera defined as the Play Camera in the export settings.
If they’re not, you’ll see this warning, where pressing the button will match the two.
If the cameras are all correctly set up, you’ll see this in the export panel, letting you know that the camera is being controlled by a Game Controls event.
Meaning that the camera defined as the Play Camera is currently used to follow a character.
With Behaviors, it is possible to add actions to the character when on Idle, when moving, and when jumping, that way creating more interactive reactions to it.
To add behaviors to your character do the following:
- Open the Game Controls event of your character(s), scroll down to the Behavior section, and open the behavior to which you want to add an action to. The current behaviors are the following:
- Idle - Actions for when the character is in a resting state.
- On Move - Actions for when the character is moving.
- On Jump - Actions for when the character is jumping.
- Create an action on the behavior that you want to adjust and select the object and the state target. Similar to other events, Behaviors can trigger transitions that target objects and trigger a state change with transitions, delay, cycle, and loop properties. Sound actions can play, pause, and stop sounds from Spline’s Original Sounds Library or your own custom sounds.