Search code examples
javascriptaframewebvr

Detect a head/camera motion with aframe


I'm in search for a motion detection in with a-frame. What I want to achieve is a detection if someone is moving his head when being in VR-Mode. Is there any property for an entity I can check? Or does the camera component itself has any position/rotaion/whatever attributes I can use for a detection?


Solution

  • https://aframe.io/docs/0.3.0/core/entity.html#listening-for-component-changes

    AFRAME.registerComponent('do-something-on-head-movement', {
      init: function () {
        var scene = this.el;
        var camera = scene.cameraEl;
    
        camera.addEventListener('componentchanged', function (evt) {
          if (evt.detail.name === 'rotation' || evt.detail.name === 'position') {
            // Do something.
          }
        });
      }
    });
    
    <a-scene do-something-on-head-movement>