# Make leaf fall

**URL:** <https://forum.8thwall.com/t/make-leaf-fall/2961>\
**Category:** Technical Support\
**Created:** [September 28, 2024, 11:20pm UTC](https://forum.8thwall.com/t/make-leaf-fall/2961 "2024-09-28T23:20:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quinxie\_Doan](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@Quinxie\_Doan](https://forum.8thwall.com/u/Quinxie_Doan)\
**Post date:** [September 28, 2024, 11:20pm UTC](https://forum.8thwall.com/t/make-leaf-fall/2961/1 "2024-09-28T23:20:07Z")

</div>

I cloned the Splat Playground studio and tried to replace the sphere with a leaf 3D model. I don’t know why the leaf doesn’t show up. This is my code, I also publish the project on my page:

```auto
import * as ecs from '@8thwall/ecs'

const spawner = ecs.registerComponent({
  name: 'sphere-spawner',

  schema: {
    spawnInterval: ecs.f32,
    leafMass: ecs.f32,
  },

  schemaDefaults: {
    spawnInterval: 150,
    leafMass: 0.1, // Adjust mass for leaf behavior
  },

  data: {
    lastSpawnTime: ecs.f64,
  },

  add: (world, component) => {
    component.data.lastSpawnTime = world.time.elapsed
  },

  tick: (world, component) => {
    const currentTime = world.time.elapsed
    const {spawnInterval, leafMass} = component.schema
    const {lastSpawnTime} = component.data

    if (currentTime - lastSpawnTime >= spawnInterval) {
      // Create a new entity for the leaf
      const leafEntity = world.createEntity()

      // Calculate a random position within a range (adjust Y position if needed for floating)
      const randomX = (Math.random() * 2 - 1) * 0.05
      const randomZ = (Math.random() * 2 - 1) * 0.05
      const randomY = 2 + (Math.random() * 0.5) // Random Y for floating effect

      // Set the position of the leaf entity
      ecs.Position.set(world, leafEntity, {x: randomX, y: randomY, z: randomZ})

      // Add the GLTF model to the entity using ecs.GltfModel
      ecs.GltfModel.set(world, leafEntity, {
        src: './assets/red_fall_leaf.glb', // Path to your .glb model file
        castShadow: true,
        receiveShadow: true,
      })

      // Add random rotation for variety
      ecs.Quaternion.set(world, leafEntity, {
        x: Math.random(),
        y: Math.random(),
        z: Math.random(),
        w: Math.random(),
      })

      // Configure physics collider (if necessary, adjust for leaves)
      ecs.Collider.set(world, leafEntity, {
        shape: ecs.ColliderShape.Box, // Adjust collider shape if needed
        mass: leafMass,
        restitution: 0.2, // Make leaves float more slowly
        friction: 0.2,
      })

      // Set a timeout to remove the entity after 10 seconds (optional)
      world.time.setTimeout(() => {
        world.deleteEntity(leafEntity)
      }, 10000) // Adjust time if you want leaves to stay longer

      // Update last spawn time
      component.data.lastSpawnTime = currentTime
    }
  },

  remove: (world, component) => {
    // Clean up code if needed
  },
})

export {spawner}

```

---

<div class="post-metadata">

**Author:** ![GeorgeButler](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.8thwall.com/georgebutler/32/1903_2.png) [@GeorgeButler](https://forum.8thwall.com/u/GeorgeButler)\
**Post date:** [September 30, 2024, 2:37pm UTC](https://forum.8thwall.com/t/make-leaf-fall/2961/2 "2024-09-30T14:37:17Z")

</div>

Are there any errors in the console? I recommend adding console.log() statements with increasing numbers or identifiers at each point where you expect a behavior to occur.
