【问题标题】:animation component along with custom component in aframe动画组件以及框架中的自定义组件
【发布时间】:2019-04-04 17:45:12
【问题描述】:

我正在尝试使用动画组件将沿 y 轴的动画添加到实体,并尝试在自定义组件中更改其沿 z 轴的位置。但是,动画组件优先,自定义组件中z轴的位置变化不起作用。

我想使用动画组件更改沿 y 轴的位置,并使用我的自定义组件更改沿 z 轴的位置。

这是我的代码 -

<a-entity id="orca" position="4 1 -18" gltf-model="#orca1" static-body animation="property: position.y; dir: alternate; dur: 1000; easing: easeInSine; loop: true; to: -1"  move></a-entity>


AFRAME.registerComponent('move', {
  schema: {
  },
  init: function() {
    this.directionVec3 = new THREE.Vector3(0, 1, 1);
  },

  tick: function(t, dt) {
   var directionVec3 = this.directionVec3;
   var currentPosition = this.el.object3D.position;
    directionVec3.z = dt/1000;
    this.el.setAttribute('position', {
      z: currentPosition.z + directionVec3.z
    }); 

    if (currentPosition.z > 10) {
      this.el.setAttribute('position', {
      z: -14
    });     
  }
 }   
});

你能帮忙吗?我选择沿 y 轴移动的动画组件的唯一原因是我使用 easeInSine 获得了平滑的正弦曲线移动。

【问题讨论】:

    标签: animation three.js aframe


    【解决方案1】:

    正如您所见,动画组件会覆盖您的位置。在这种情况下,您可以将组件应用到父实体以避免冲突:

    <a-entity move>
      <a-entity id="orca" position="4 1 -18" gltf-model="#orca1" static-body animation="property: position.y; dir: alternate; dur: 1000; easing: easeInSine; loop: true; to: -1">
      </a-entity>
    </a-entity>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 2015-12-06
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多