You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Aframe v0.8.0中begin:click触发旋转动画功能失效问题

Fixing Click-Triggered Rotation Animation in A-Frame

It looks like your click-triggered animation isn’t working due to a couple of key missing pieces and a small syntax error. Let’s break down how to get this working properly:

Key Issues in Your Current Code

  • Missing Click Detection Setup: A-Frame needs a cursor and raycaster to detect click interactions on 3D objects. The cursor-listener component alone can’t pick up clicks without these core interaction tools.
  • Syntax Error in Position: Your position value has a typo (-.0.4 should be -0.4), which might be placing the object where you can’t click it at all.
  • Missing Animation Duration: Without a dur (duration) property, the animation will complete instantly—making it look like nothing happened, even if it runs.

Fixed Code Example

Here’s an updated version that addresses all these issues:

<a-scene>
  <!-- Add camera with cursor and raycaster to enable click detection -->
  <a-camera 
    cursor="rayOrigin: mouse" 
    raycaster="objects: [clickable]"
  ></a-camera>

  <!-- Updated object with clickable class, fixed position, and working animation -->
  <a-entity 
    class="clickable"
    cursor-listener 
    id="butt" 
    position="-0.4 -0.1 0.5" 
    obj-model="obj: #but" 
    scale="1 1 1" 
    rotation="0 0 0" 
    animation__rotate="begin:click; property: rotation; to: 0 360 0; dur: 1000; easing: linear"
  >
  </a-entity>
</a-scene>

What Changed?

  1. Added Cursor & Raycaster: The camera now has a cursor (for mouse/VR pointer) and raycaster (to detect intersections with objects marked as clickable). This is essential for triggering click events on your 3D object.
  2. Fixed Position Typo: Corrected -.0.4 to -0.4 so your object is placed correctly in the scene where you can click it.
  3. Added Animation Duration: The dur: 1000 sets the rotation to take 1 second, so you can actually see the animation play out. The easing: linear ensures smooth, consistent rotation.
  4. Added clickable Class: This tells the raycaster to only check for clicks on objects with this class, which is more efficient than checking every object in the scene.

If you want the rotation to loop continuously after the first click, you can add loop: true to the animation component. Just note that once it starts looping, it won’t stop until you trigger another animation or pause it manually.

内容的提问来源于stack exchange,提问作者andy ram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:36:42