API

Getting Started - Chapter 2 - Ground

Grounding the World

At the moment, we have a box floating in space. To make the scene more world-like, let's add ground and think of our box as a building set on it.

Adding ground is simple:

import { MeshBuilder } from "@babylonjs/core/Meshes/meshBuilder";
const ground = MeshBuilder.CreateGround("ground", { width: 10, height: 10 });

We need to create ground large enough to place some buildings (boxes) on, so the options parameter has two properties set: width in the x direction and height in the z direction. (Yes, we agree: since y is vertical, it would make more sense for the properties to be width and depth.)

Adding a Ground Playground

The immediate thing to note is that the ground cuts through the middle of the box. This is because meshes are positioned at the origin when they are created.

ground

We need to move the box up half its height using

box.position.y = 0.5; //box created with default size so height is 1
Adjusting the Box position.

house 0

Currently our world is silent. Let's add some sound.