World

The World service is used for code that needs to interact with the world like spawning actors, finding actors or controlling directional light.

Access the world by injecting it in your services, actors and component classes.


@Service()
class Game extends GameInstance {
    private world = inject(World)
    
    onStart() {
        
    }
    
}

Directional Light

By default, every scene has directional light which produces shadows. You may want to access this to update the direction or intensity at runtime.

@Service()
class Game extends GameInstance {
    private world = inject(World)
    
    onStart() {
        this.world.directionalLight.intensity = 0.2 
        this.world.directionalLight.direction.applyAxisAngle(new THREE.Vector3(0,0,1), Math.PI / 2)

    }
    
}

The directional light exposes the following fields

  • direction: Vector3 - The direction vector can be updated to change the direction of the light. This can be used to emulate a sun.

  • intensity: number - How bright the light should be.

  • position: Vector3 - The position of the directional light instance. This can not be changed; instead, change the direction.

Last updated