0

I have following component which I attach to all cameras in the scene and register actions for each checkpoint which user can enter with this camera. Right now it works by checking camera position relative to cameras starting point, but how can I get that cameras world position and be sure that this is active camera? Since seems that inactive cameras keep emitting events when some physics change their location.

AFRAME.registerComponent('user-checkpoints', {
  init: function () {
    var self = this;
    this.el.addEventListener('componentchanged', isOnCheckPoint);
    // Is user in checkpoint
    function isOnCheckPoint (evt) {
      // We don't want such precision what event emits
      if (evt.detail.name !== 'position' || (
        (evt.detail.oldData.x).toFixed(1) === (evt.detail.newData.x).toFixed(1) && 
        (evt.detail.oldData.y).toFixed(1) === (evt.detail.newData.y).toFixed(1) && 
        (evt.detail.oldData.z).toFixed(1) === (evt.detail.newData.z).toFixed(1))
    ) { return; }

    // Position has changed enough to check it
    self.LookForCheckPoint(evt.detail.newData.x, evt.detail.newData.y, evt.detail.newData.z);
    }
  },
  LookForCheckPoint: function (x, y, z) {
    // All the chekpoints are checked here
    console.log('x:' + x + ' y:' + y + ' z:' + z);
  }
});

EDIT: I got answer for my question from other thread at How to listen to camera's world position in A-Frame?

Community
  • 1
  • 1
mkungla
  • 3,390
  • 1
  • 26
  • 37

1 Answers1

0

You can check if the camera is active by doing:

el.getAttribute('camera').active === true

Diego Marcos
  • 4,502
  • 3
  • 15
  • 20