How to change the rotation axis for an animated A-Frame object?

こ雲淡風輕ζ 提交于 2019-12-02 06:37:56

问题


Somewhat related to this question, I can't seem to find an 'in-framework' way to change the rotational axis for an A-Frame object (like Earth's tilted axis, for example).

The linked question refers to changing the rotation pivot point by wrapping the object in a parent entity which will offset the child entity (see below):

<a-entity rotation="0 45 0">        <!-- Parent entity -->
  <a-box position="0 1 0"></a-box>  <!-- Child entity -->
</a-entity>

I've adopted a similar method but rather than offset the pivot point, I've tried to change the rotation axis. When adding an animation to the parent, the rotation is always along the global Y-axis, rather than the local (parent's) rotated Y-axis:

<a-entity rotation="0 0 25">       <!-- Parent entity -->
  <a-animation
    attribute="rotation"
    easing="linear"
    dur="60000"
    to="0 360 0"
    repeat="indefinite">
  </a-animation>                   <!-- Animates parent -->
  <a-box position="0 0 0></a-box>  <!-- Child entity -->
<a-entity rotation="0 0 25">

Does anyone know how best to change the axis from global- to local-space, or if there's a way to animate around a tilted axis?


回答1:


I think you can add an additional parent entity around everything and rotate that.

<a-entity>  <!-- Grandparent entity -->
  <a-animation
    attribute="rotation"
    easing="linear"
    dur="60000"
    to="0 360 0"
    repeat="indefinite">
  </a-animation>           
  <a-entity rotation="0 0 25">        <!-- Parent entity --> 
    <a-box position="0 0 0></a-box>  <!-- Child entity -->
  </a-entity>
</a-entity>

Open the A-Frame Inspector (ctrl + alt + i) and play with the rotation to see which way you want to rotate.



来源:https://stackoverflow.com/questions/42838501/how-to-change-the-rotation-axis-for-an-animated-a-frame-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!