在 Aframe 中移动相机

Move camera in Aframe

我看到了一些代码,我试着把它们编译在一起。它不起作用,我可能会错过一些东西。

Glitch full code

两期,

  • 函数名称 (movekamera) 而不是调用 (movekamera())
  • <a-animation> 已弃用 - 请改用 animation

您的代码进行了这些更改:

 <script src="https://aframe.io/releases/1.1.0/aframe.min.js"></script>

    <a-scene background="color: #FAFAFA">
      <a-entity
        id="mouseCursor"
        cursor="rayOrigin: mouse"
        raycaster="objects: #box,#plane,#cylinder"
      ></a-entity>

      <a-entity
        id="box"
        geometry="primitive: box"
        material="color: red"
        position="-1 1 -3"
        rotation="0 30 0"
        onclick="kameramove_1()"
      ></a-entity>
      <a-cylinder
        id="cylinder"
        position="1 0.75 -3"
        radius="0.5"
        height="1.5"
        color="#FFC65D"
        shadow
        onclick="kameramove_1_back()"
      ></a-cylinder>
      <a-plane
        id="plane"
        position="0 0 -4"
        rotation="-90 0 0"
        width="4"
        height="4"
        color="#7BC8A4"
        onclick="kameramove_1()"
      >
      </a-plane>
      <a-entity movement-controls="fly: true" position="0 0 0"></a-entity>
      <a-entity camera position="0 1.6 0" look-controls></a-entity>

      <a-entity id="camentity" rotation="0 0 0"
      animation__1="property: position; from: 0 0 0; to: -4 0 -5; dur: 500; 
      startEvents: movecam_1"
      animation__bc ="property: position; to: 0 0 0; from: -4 0 -5; dur: 500; startEvents: movecam_1_bc">
        <a-camera id="cam"></a-camera>
      </a-entity>
    </a-scene>
    <script>
      function kameramove_1() {
        document.querySelector("#cam").emit("movecam_1");
      }

      function kameramove_1_back() {
        document.querySelector("#cam").emit("movecam_1_bc");
      }
    </script>