2016-12-12 2 views

Antwort

2

-Komponente, die Kugel Kameradrehung und Updates mit tick kontinuierlich überprüft:

AFRAME.registerComponent('rotation-updater', { 
    tick: function() { 
    var sphere = this.el; 
    var camera = this.el.sceneEl.cameraEl; 

    var cameraRotation = camera.getAttribute('rotation'); 
    // var sphereRotation = DO SOMETHING WITH CAMERA ROTATION. 
    sphere.setAttribute('rotation', sphereRotation); 
    } 
}); 
+0

Hallo Kevin! Warum nicht neue AFRAME.TWEEN.Tween() .blabla(). Start() erstellen und .update() im Tick verwenden? – Appeiron

+0

OP wollte es abhängig von der Kameradrehung. Tween kann nur grundlegende Interpolationen durchführen. – ngokevin

+0

Aber wenn ich Easing auch verwenden möchte, kann ich nicht einfach eine solche Abhilfe schaffen :(Trotzdem Danke. – Appeiron

0

Nun kann diese verwendet werden, wenn Animation endlich sein sollte:

AFRAME.registerComponent('camera-seeker', { 
    init() { 
     this.CAMERA = document.querySelector('#player'); 
     this.newCords = {}; 
     this.setupAnimation(); 
    }, 

    setupAnimation() { 
     let el = this.el; 
     var this_ = this; 
     seekAnim = new AFRAME.TWEEN.Tween(this.el.getAttribute('rotation')) 
      .to(this.newCords, 30000) 
      .easing(AFRAME.TWEEN.Easing.Quadratic.Out) 
      .onUpdate(function() { 
       el.setAttribute('rotation', `${this.x}, ${this.y}, ${this.z}`); 
      }) 
      .repeat(Infinity) 
      .start(); 
    }, 

    tick() { 
     if (!isGameStart()) return; 
     if (AFRAME.utils.coordinates.stringify(this.CAMERA.getAttribute('rotation')) !== AFRAME.utils.coordinates.stringify(this.el.getAttribute('rotation'))) { 
      Object.assign(this.newCords, this.CAMERA.getAttribute('rotation')); 
     } 
    } 
});