Back to Content

Creating a 3D Walkthrough - Tutorial


This tutorial shows how to create first person style camera controller with which you can walk trough a 3d scene and collide with walls, using Coppercube.

Start - create your 3D scene

To start, we need a 3D scene where we can walk through. Import a 3D Model, add a skybox, lights and whatever you want until you like the 3D scene. You can also use the 'Create plane' and 'Create box' commands or the prefabs to create a very simple scene for testing purposes for this tutorial. The scene I am using in this example looks like this, a simple room with a stair and some windows in it:


A scene for this example

Note: You can also quickly create a 3D world mesh by using the room generator built into CopperCube: Use the Menu Command 'Edit -> Insert -> Create a room mesh from a 2D map' and paint a simple room using that.

Adding a Camera

Once you have set up your scene, to the important part: We need the camera so the user can walk around in the 3D scene. Click on the 'Scene editing' tab and click the camera symbol to create a new camera (Alternatively, use the menu: Edit -> Insert -> Create a Camera).
A dialog like this should appear:


The camera creation dialog


Select the 'First Person Shooter Camera'. Also be sure that both options "Collides against geometry when moved" and "When starting the scene, this is the first active camera" is checked. Clicking 'OK' creates a new camera and selects it:


The newly created first person shooter camera


Notice the yellow outline of an ellipsoid around the camera. This is the collision body, basically the size of the person walking around in the scene. Maybe you need to adjust the size of this ellipsoid, so that it matches your scene. You need to make it big enough that it is possible for the user to climb stairs, but small enough to fit through doors.
You can use the scale tool (shortcut 'R') to change the size of the ellipsoid.


Adjusting the size of the collision ellipsoid


Also, be sure that the yellow ellipsoid 'flies' a bit in the air and that it doesn't touch any wall or floor in the beginning, otherwise the user would be stuck in that wall at the start of the application and would not be able to move.

Now go to the properties window of the camera, open the 'Behaviors' tab and select the 'First Person Shooter style controlled' behavior:


The behaviors of the created camera


You can set various options there, like the movement or rotation speed. If you want the camera to be able to fly instead of walk, you can check the 'CanFly' option, but you need also to uncheck the 'AffectedByGravity' box then.
The second behavior in the camera is the 'Collide when moved' behavior:


The 'Collide when moved' behavior


This behavior prevents the camera moving through walls. If you want the user be able to move trough walls, simply click the '-' button and erase the behavior.
the 'Size' attribute is the size of the Ellipsoid, you can also manually adjust it here if you want. If you want to adjust the position of the head or the eyes in the collision body, change the value in 'Relative Position'. For a bigger or lower gravity, adjust the value of 'Gravity' which you can find when selecting the root node of the scene in the SceneGraph Explorer. Choose for example 100 for a very strong gravity, or 0 for no gravity.


That's it, now you can walk around in your 3D scene by simply testing your application (menu: Tools -> Test as Windows .exe or Flash .swf). If you have more than one camera in the scene, ensure that the camera with the ellipsoid has the setting 'active' enabled in the attributes tab of the property window.