Floor
Updated
Lets the entity’s meshes cast and/or receive shadows from lights.
- Type
ent-floor- Script class
FloorMeshEntity- Family
- Meshes
Overview
Section titled “Overview”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):widthandheightof the slab, in metres.color,roughnessandmetalness(material): how the ground looks.frictionandrestitution(Box Collider): how slippery and how bouncy the ground is for physics objects.receive(Shadow): whether shadows show on the floor.
Set it up
Section titled “Set it up”- Add a Floor entity to the scene (see Scenes and hierarchy) and place it where the ground should be.
- Set the Geometry’s
widthandheightto the size of the area. The collider follows. - Set the material’s
colorandroughness, or replace the material, for example with a Reflector material for a polished floor. - To react to what touches the floor, add a Signal Emitter with a signal before play starts.
- Add a Grass component to grow grass on it, if you like.
Examples
Section titled “Examples”Size the arena from a slot
Section titled “Size the arena from a slot”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.
#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 namedarenaSizethat 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;setPropschanges only the keys passed.
Log what lands on the floor
Section titled “Log what lands on the floor”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.
#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-enterwhen a solid contact begins. The Signal Emitter puts it on thefloorsignal. event.data.otherEntityIdis the entity that touched the floor. It is absent for geometry that belongs to no entity, which the check skips.findEntityaccepts 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.
A lava floor that sends objects back
Section titled “A lava floor that sends objects back”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.
#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
emissiveand anemissiveIntensityabove0; values above 1 also glow under bloom. getWorldPosition(spot)reads the safe spot’s position once, into a vector made once.setPositionmoves 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.
Components
Section titled “Components”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- |
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- |
Starts with | One | Physically based metal/roughness material; the default for most surfaces. |
| Box Collider | comp- |
Required | Several | Box-shaped collision, fitted to the mesh by default. |
| Navmesh Walkable | comp- |
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({ … }).
Shadow
Section titled “Shadow”| Prop | Default | Range |
|---|---|---|
cast |
false |
|
receive |
true |
Geometry
Section titled “Geometry”| Prop | Default | Range |
|---|---|---|
shape |
"plane" |
|
params |
{"width":30,"height":30} |
Standard Material
Section titled “Standard Material”| Prop | Default | Range |
|---|---|---|
color |
"#11aa00" |
|
opacity |
1 |
0 ≤ x ≤ 1 |
wireframe |
false |
|
side |
"front" |
|
emissive |
"#ffffff" |
|
emissive |
0 |
0 ≤ x ≤ 1000 |
flatShading |
false |
|
roughness |
0.8 |
0 ≤ x ≤ 1 |
metalness |
0 |
0 ≤ x ≤ 1 |
Box Collider
Section titled “Box Collider”| 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 |
|
collision |
0 |
0 ≤ x ≤ 15 |
borderRadius |
0 |
0 ≤ x ≤ 100 |
size |
{"x":30,"y":0. |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
Shadow::changePhysicsCollider::collision-enterPhysicsCollider::collision-exitPhysicsCollider::intersection-enterPhysicsCollider::intersection-exit
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
A character with a Character Controller and no player controls runs towards the main camera every frame with move, and stops two metres short.
Drag to orbit the camera around the yard: the chaser turns and runs after you, and stops when it is close. Scroll to zoom.
From a script
Section titled “From a script”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.
#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);}