Skip to content

Floor

Updated

Lets the entity’s meshes cast and/or receive shadows from lights.

Type
ent-floor
Script class
FloorMeshEntity
Family
Meshes

A Floor is a solid, walkable ground slab: the quickest way to give a scene something to stand on. It is a flat primitive with three things already set up for ground:

  • a Geometry and a material that draw it, like a Primitive Mesh: a new Floor is a 30 × 30 m green plane with a Standard material;
  • a Box Collider sized to the slab, so players, characters and physics objects rest on it. The Floor keeps that collider matched to its geometry when you resize it;
  • a Navmesh Walkable component, so its surface counts as ground when the navigation mesh is baked.

It also starts with a Shadow component set to receive shadows but not cast them, which is what a ground surface needs.

Use a Floor for rooms, arenas, stages and test scenes. For hills and landscapes, use a Terrain. For a shape that is not ground, use a Primitive Mesh, which has no collider until you add one.

The props that matter most:

  • params (Geometry): width and height of the slab, in metres.
  • color, roughness and metalness (material): how the ground looks.
  • friction and restitution (Box Collider): how slippery and how bouncy the ground is for physics objects.
  • receive (Shadow): whether shadows show on the floor.
  1. Add a Floor entity to the scene (see Scenes and hierarchy) and place it where the ground should be.
  2. Set the Geometry’s width and height to the size of the area. The collider follows.
  3. Set the material’s color and roughness, or replace the material, for example with a Reflector material for a polished floor.
  4. To react to what touches the floor, add a Signal Emitter with a signal before play starts.
  5. Add a Grass component to grow grass on it, if you like.

Goal: let a designer set the arena size in the editor, and build the floor to match when the scene starts.

The Behavior entity is a child of the Floor.

ArenaFloor.jx
#pragma slot(ref=arenaSize, type=Number, min=5, max=200, default=40)
#pragma lifecycle(startup)
function startup() {
const floor = self.parent;
floor.getComponent(GeometryComponent).setProps({
shape: 'plane',
params: { width: arenaSize, height: arenaSize },
});
floor.getComponent(MaterialComponent).setProps({ color: '#3a3f47', roughness: 0.6 });
log('Arena floor is', arenaSize, 'm across');
}
  • #pragma slot(...) creates an editor field named arenaSize that the script reads as a variable.
  • Changing the Geometry rebuilds the slab once. The Floor resizes its Box Collider to match, so the walkable area always equals the visible one.
  • getComponent(MaterialComponent) reaches the material whatever its kind; setProps changes only the keys passed.

Goal: report each object that comes to rest on the floor, for example to count crates a player has knocked down.

The Floor has a Signal Emitter whose signal is floor.

FloorContacts.jx
#pragma lifecycle(startup)
let fallen = 0;
function startup() {
on('floor', (event) => {
if (event.eventType !== EventType.PhysicsCollider.CollisionEnter) return;
const other = event.data.otherEntityId && findEntity(event.data.otherEntityId);
if (!other || !other.name.startsWith('Crate')) return;
fallen += 1;
log(other.name, 'hit the floor;', fallen, 'down so far');
});
}
  • The Floor’s Box Collider sends PhysicsCollider::collision-enter when a solid contact begins. The Signal Emitter puts it on the floor signal.
  • event.data.otherEntityId is the entity that touched the floor. It is absent for geometry that belongs to no entity, which the check skips.
  • findEntity accepts an id as well as a name.
  • Collision events are wired when the physics body is built, at the start of play. The Signal Emitter must be on the Floor by then.

Goal: anything that touches the lava returns to a safe spot, a common pattern for platform games.

The lava Floor has a Signal Emitter whose signal is lava, and a Group named Safe Spot marks where objects return.

LavaFloor.jx
#pragma lifecycle(startup)
const spot = new THREE.Vector3();
function startup() {
const lava = findEntity('Lava');
lava.getComponent(MaterialComponent).setProps({ color: '#ff4400', emissive: '#ff2200', emissiveIntensity: 1.5 });
findEntity('Safe Spot').getWorldPosition(spot);
on('lava', (event) => {
if (event.eventType !== EventType.PhysicsCollider.CollisionEnter) return;
const other = event.data.otherEntityId && findEntity(event.data.otherEntityId);
if (!other) return;
other.setPosition(spot.x, spot.y, spot.z);
log(other.name, 'fell into the lava');
});
}
  • The lava glows with emissive and an emissiveIntensity above 0; values above 1 also glow under bloom.
  • getWorldPosition(spot) reads the safe spot’s position once, into a vector made once.
  • setPosition moves the object and keeps its physics body in step. It places the entity in its parent’s space, which equals world space for objects at the top of the scene.
  • Resize a Floor through its Geometry: the Floor then resizes its Box Collider to match.
  • The Floor sizes only its first Box Collider to the slab. Extra colliders you add keep their own size.
  • A new Floor casts no shadow. Leave it that way: a ground surface only needs to receive them.

What a new Floor is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Shadow comp-shadow Starts with One Lets the entity’s meshes cast and/or receive shadows from lights.
Geometry comp-geometry Required One A built-in primitive shape: box, sphere, plane, cylinder, ring and more.
Standard Material comp-standard-material Starts with One Physically based metal/roughness material; the default for most surfaces.
Box Collider comp-box-collider Required Several Box-shaped collision, fitted to the mesh by default.
Navmesh Walkable comp-navmesh-walkable Starts with One Marks this entity’s surfaces as ground agents walk on when the navmesh is baked. Too steep stays unwalkable.

You can also add 22 optional components, such as Animation Graph, Animation Timeline, Basic Material, Capsule Collider, Cone Collider, Contact Shadow.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
cast false
receive true
Prop Default Range
shape "plane"
params {"width":30,"height":30}
Prop Default Range
color "#11aa00"
opacity 1 0 ≤ x ≤ 1
wireframe false
side "front"
emissive "#ffffff"
emissiveIntensity 0 0 ≤ x ≤ 1000
flatShading false
roughness 0.8 0 ≤ x ≤ 1
metalness 0 0 ≤ x ≤ 1
Prop Default Range
offset {"x":0,"y":0,"z":0}
rotation {"x":0,"y":0,"z":0}
friction 0.5 0 ≤ x ≤ 5
restitution 0 0 ≤ x ≤ 1
sensor false
collisionLayer 0 0 ≤ x ≤ 15
borderRadius 0 0 ≤ x ≤ 100
size {"x":30,"y":0.04,"z":30}

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Shadow::change
  • PhysicsCollider::collision-enter
  • PhysicsCollider::collision-exit
  • PhysicsCollider::intersection-enter
  • PhysicsCollider::intersection-exit

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Floor.

FloorMeshEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My Floor');
if (!(entity instanceof FloorMeshEntity)) return;
// Its Shadow component holds the settings listed under Props.
const component = entity.getComponent(ShadowComponent);
log(component.props);
}