Back to Content

Doing Actions when clicked on Items


This tutorial shows how to define actions like hiding objects, playing sounds or opening websites when the user clicks on an item in your Coppercube scene.

Start - create your 3D scene

To start, we need a 3D scene where some 3D objects are which we can interact with. Simply create 4 random spheres, boxes and cylinders, and a 'Simple Camera' using the Toolbar (or use the menu Edit -> Insert). Let the target of the simple camera look at the objects, so that the scene looks a bit like this:


The scene for this example


So when you publish and start the 3D scene, you should see the spheres and meshes in the view, and have a mouse cursor with which you can click at these items.

Defining events and actions

Once you have set up your scene, to the important part: We want to make one of the items - let's say the cylinder disappear when we click on another item, the sphere. To do this, select the sphere and go to the 'Behavior' tab in the property window. There, click on the '+' button to add a new behavior:


Adding a behavior to the sphere


By selecting 'when clicked do something', you can add a behavior which triggers an action when the user clicks on the sphere. There are other behaviors to choose from as well, like the 'on proximity do something' behavior which triggers an action when something comes near this item, but for this tutorial, we use the 'when clicked do something' behavior.

After you added that behavior, there are some options visible. Ignore them for now, and simple click the 'Action' entry, to define what should happen if this object is clicked. When you click on the '...' button, a dialog should open where you can edit a list of actions. Click on the '+' button and a list of actions should appear:


The action editing dialog


Select the 'Hide or unhide a scene node' action, which will make it possible to make another object visible or invisible. There are 3 modes to choose from: 'Make Invisible' which will hide an object, 'Make Visible' which will show it or 'Toggle Visibility' which will make it visible if it is invisible and invisible if it is visible. The 'Toggle Visibility' is ok for us and should be selected by default, so leave it as it is. We now only need to select which Scene Node to hide: Click the 'Select' option in the 'Change which Scene Node' entry:


Selecting which scene node to hide or unhide


A dialog to select a scene node should pop up and you could select the cube or the cylinder.


Selecting which scene node to hide or unhide


And that's it. If you now publish your scene (Tools -> Test as ... Application) and click on the sphere, the other item should disappear. If you click on it again, it should appear again.

There are a lot of other actions to chose from, like changing the position of a scene node, playing a sound or opening a website. Just try it out.