aframe-在运行时设置相机位置 [英] aframe - Set camera position at runtime

查看:629
本文介绍了aframe-在运行时设置相机位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在a场景中,我尝试在运行时更改相机的位置。 DOM属性发生变化,但相机没有移动。

In a a-scene, I try to change my camera position at runtime. The DOM property changes but the camera does not move.

我可能错过了什么?

我的js代码:
document.querySelector('#myCameraPosition')。setAttribute('position','0 0 0');

我的a场景:

My a-scene:

    <a-entity id="myCameraPosition" position="0 0 50">
        <a-entity id="myCamera" camera look-controls keyboard-controls>
        </a-entity>
    </a-entity>



推荐答案

在相机周围创建包装器实体:

Create a wrapper entity around the camera:

<a-entity id='cameraWrapper' position="0 0 0">
  <a-camera></a-camera>
</a-entity>

然后更改包装器的位置:

Then change position of the wrapper:

document.querySelector("#cameraWrapper").object3D.position.set(1, 1, 1);

这篇关于aframe-在运行时设置相机位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆