Hello! Please choose your
desired language:
Dismiss

User data

Track user position and rotation

The Camera object exposes information about the user’s point of view in your scene.

  • camera.position returns a 3D vector with the user’s coordinates relative to the scene.
  • camera.rotation returns a quaternion with the user’s rotation.

Tip: You can also obtain the user’s rotation expressed in Euler angles (as an x, y and z vector) by writing camera.rotation.eulerAngles.

const camera = Camera.instance

class CameraTrackSystem {
  update() {
    log(camera.position)
    log(camera.rotation.eulerAngles)
  }
}

The example above logs the user’s position and rotation on each frame.

const camera = Camera.instance

class SomeSystem implements ISystem {
  constructor() {
    super(Transform)
  }

  update() {
    for (let i in this.entities) {
      const entity = this.entities[i]
      const transform = entity.getComponent(Transform)
      transform.rotation.copy(camera.rotation)
    }
  }
}

const cube = new Entity()
const shape = new BoxShape()
const transform = new Transform()
transform.position.set(5, 1, 5)
cube.addComponent(shape)
cube.addComponent(transform)

engine.addEntity(cube)
engine.addSystem(new SomeSystem())

The example above uses the user’s rotation to set that of a cube in the scene.

Get player’s public Ethereum key

To get a user’s Ethereum public key, use the EthereumController library. See scene blockchain operations for details.