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.
There are a few key properties for this behavior:
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:
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:
In a new scene, I created a Plane to act as the ground, then with the default cube applied the following behavior:
When set to Object moved by physics engine, the object becomes part of the simulation. We now have the following properties available:
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:
Now let’s create a Sphere, and add Collide When Moved and When A Key Is Pressed to the newly created sphere, like so:
Set the action on the key pressed Behavior to the following:
This will move the object along the Z axis, 100 units over 1 seconds time. Now run your scene:
TADA, simple and easy physics simulation!