Programming Your Game

So at this point, we’ve created a game world, populated it with “stuff” and set up a camera… now it’s time to add some actual logic to our game. How exactly do you script or program in Coppercube? This is done with a combination of Behaviors and Actions. With the cubeMesh1 object selected, in the Properties tab, select the Behaviour tab, then click the + icon.

CopperCube 6 - Programming your Game - Behaviors and Actions

Now select the predefined behavior you want to add to your object. There are several different behaviors you can add to a game object to quickly define its capabilities.

CopperCube 6 - Programming your Game - Game Behaviors

Let’s start with a very simple cause and effect ability. Select Effect Behaviors and choose Behaviors triggered by events->When a key is pressed do something.

CopperCube 6 - Programming your Game - Behaviors triggered by events

Now you will see in the Properties we can define which key to press and whether to fire the action when the key is pressed or when it is released.

CopperCube 6 - Programming your Game - KeyEvent

Next we define the Action. Click the … to the right of Action.

CopperCube 6 - Programming your Game - Action

This will display the Actions window. Click the + icon to add a new Action and a menu will be displayed:

CopperCube 6 - Programming your Game - New Action

In this example, let’s just play a Sound when the Spacebar is pressed. Select Game and Sound->Play a sound.

CopperCube 6 - Programming your Game - Game and Sound

This will display a new set of options in the Properties section specific to this action.

CopperCube 6 - Programming your Game - Properties

Click the SoundFileName field and select a compatible audio file from the supported file formats. CopperCube supports a large number of audio formats:

CopperCube 6 - Programming your Game - SoundFileName

Now run your game, when you hit the Spacebar or whatever key you specified to trigger the action, your sound effect should play.

On the topic of sound effects, it’s possible you want to have ambient sounds or background music playing in your scene. This can easily be accomplished using the 3D Sound node type, in the Create Panel:

CopperCube 6 - Programming your Game - 3D Sound node

You can then specify the sound’s position within the Scene, like so:

CopperCube 6 - Programming your Game - Scene

You can then specify the sound in the Properties panel.

CopperCube 6 - Programming your Game - Properties Panel

Not the 3DRadius of the sound property. This will determine how far within the scene that sound should be heard as your camera navigates around the scene.

Now let’s look at providing simple movement controls to our cube, giving us the ability to drive it around our world. Simply select the cube, Add Behavior, Game behaviors->Object or Person controlled by keyboard.

CopperCube 6 - Programming your Game - Add Behavior

There are now several default properties you can configure how this character will move around:

CopperCube 6 - Programming your Game - Default Properties

In this case, let’s just stick with the default values. If you have a more complicated model, such as one with several different animations, or if you want to change the way acceleration works, you can specify all those values here. At this point, you should be able to fly around in your scene using the WASD keys. You may also notice that you can currently fly through objects… not exactly desired behavior!

Scroll to Top