Block Entities
Common Uses & Examples
Moving Platform
const blockPlatform = new Entity({
blockTextureUri: 'blocks/grass', // A texture URI without a file extension will use a folder and look for the textures for each face in the folder (-x.png, +x.png, -y.png, +y.png, -z.png, +z.png)
blockHalfExtents: { x: 1, y: 0.5, z: 1 },
rigidBodyOptions: {
type: RigidBodyType.KINEMATIC_VELOCITY, // Kinematic means platform won't be effected by external physics, including gravity
linearVelocity: { x: 0, y: 0, z: 3 }, // A starting velocity that won't change because it's kinematic
},
});
// Clamp the z range the platform moves back and forth between
blockPlatform.on(EntityEvent.TICK, () => {
const position = blockPlatform.getTranslation();
if (position.z < -9) {
blockPlatform.setLinearVelocity({ x: 0, y: 0, z: 3 });
}
if (position.z > 8) {
blockPlatform.setLinearVelocity({ x: 0, y: 0, z: -3 });
}
});
blockPlatform.spawn(world, { x: 3, y: 3, z: -7 });Pushable Block
Pushable Block With Locked Rotations & Translations
Teleporting Block
Heavy Pushable Block
Last updated
