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.
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 it’s capabilities.
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.
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.
Next we define the Action. Click the … to the right of Action.
This will display the Actions window. Click the + icon to add a new Action and a menu will be displayed:
In this example, let’s just play a Sound when the Spacebar is pressed. Select Game and Sound->Play a sound.
This will display a new set of options in the Properties section specific to this action.
Click the SoundFileName field and select a compatible audio file from the supported file formats. CopperCube supports a large number of audio formats:
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:
You can then specify the sounds position within the Scene, like so:
You can then specify the sound in the 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.
There are now several default properties you can configure how this character will move around:
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!