We’d love to hear from you. Whether you have a question that you’d like us to answer as part of our FAQ,  you’ve identified something that just doesn’t quite look right in one of our tutorials, you have a business opportunity or for any other reason, please use this simple form to contact us.

We’ll do our best to provide a prompt response.

Like what you see?...pass it on!

Collisions and Physics

So if flying through mountains isn’t the desired behavior; Speaking of behaviors, that’s exactly how we can fix this. Select the cube object, go to the Behaviors tab in Properties, hit the + icon and add the Collide when moved.

CopperCube 6 - Collisions and Physics - Collide when moved

There are a few key properties for this behavior:

CopperCube 6 - Collisions and Physics - Key Properties

Click AffectedByGravity if you want the object to be… um, affected by gravity. Click EnableInclination if you want your object to rotate to match the angle of hills it’s climbing or declining. Now your object will travel flawlessly around the scene. Notice when you select your object now, there is a capsule about it in yellow:

CopperCube 6 - Collisions and Physics - Physics Simulation

This determines the collision shape of our object, with the size being configured by the Size property, while it’s position relative to our game object is set by the RelativePosition. Tweak this to properly represent the dimensions of your object.

So far we’ve just used the simple collision. If you want a more complicated physics simulation we can set that in game options. Keep in mind that it’s not available on all platforms. For example, WebGL only has Collisions available. To enable more complicated physics, go into the settings for the platform you are building for and switch the physics engine from Only Collision to Physics Simulation:

Clipboard-Image_428

In a new scene, I created a Plane to act as the ground, then with the default cube applied the following behavior:

CopperCube 6 - Collisions and Physics

When set to Object moved by physics engine, the object becomes part of the simulation. We now have the following properties available:

CopperCube 6 - Collisions and Physics - Object moved by Physics Engine

You can now define the shape of the object to use in the simulation instead of being forced to use a capsule like earlier. You can instead pick Box, Sphere, Cylinder or yes… Capsule. Additionally you can see the density and size. Now select the cube, right click it in SceneGraph and select Clone. Clone the box several time and stack like this:

CopperCube 6 - Collisions and Physics - SceneGraph

Now let’s create a Sphere, and add Collide When Moved and When A Key Is Pressed to the newly created sphere, like so:

CopperCube 6 - Collisions and Physics - Collide when Moved

Set the action on the key pressed Behavior to the following:

CopperCube 6 - Collisions and Physics - Key Pressed Behavior

This will move the object along the Z axis, 100 units over 1 seconds time. Now run your scene:

CopperCube 6 - Collisions and Physics - Run your Scene

TADA, simple and easy physics simulation!

Programming Your Game<<PreviousTable of ContentsNext>>Extending CopperCube

Like what you see?...pass it on!

script ends --->