A-frame consitanly 动画 gltf 去相机 A-frame 的位置
A-frame consitatnly animate gltf to go to position of camera A-frame
我正在使用 A 帧 (https://aframe.io) 创建一个虚拟现实场景,我想知道如何为 gltf 模型制作动画以始终跟随相机。例如,我想使用 A 帧的动画 属性 并定位我的模型,以便它始终跟随玩家。如果玩家向前移动 10 米,gltf 将动画向前移动 10 space。如果玩家向左移动 10spaces,无论玩家移动到哪里,摄像机都会跟随玩家。我想让 gltf 模型始终跟随相机。如何才能做到这一点?我的 gltf 模型代码:
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<a-scene>
<a-gltf-model class="cube" mixin="cube" animation=' property: position; dur: 2500; from: 0 2.3 -1; to: 0 2.5 -1; dir: alternate; autoplay: true; easing: linear; loop: true;' src="https://cdn.glitch.com/bb5471f0-16f5-4309-8c7c-52310dc4ff58%2FRobotfr.glb?v=1625527911166" position="0 2.3 -1"scale="1.2 1.2 1.2" speech-command__show="command: assistant; type: attribute; attribute: visible; value: true;"speech-command__hide="command: hide; type: attribute; attribute: visible; value: false;"></a-gltf-model>
</a-scene>
其实你问的是相机运动的第三人称视角相关的问题。这可以通过重新设置相机的父级轻松完成,并且您需要为相机添加一些偏移量,以便它始终看起来在相机前面
<a-camera>
<!-- The object with the same transform as the camera + some offset -->
<a-entity gltf-model="./scene.gltf" position="0 0 -0.5"></a-entity>
</a-camera>
如果这不起作用,请尝试创建和使用这样的组件
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-orbit-controls@1.2.0/dist/aframe-orbit-controls.min.js"></script>
<script>
AFRAME.registerComponent("follow-box", {
schema: {
target: {type: "selector"}
},
tick: (function() {
const tmpv = new THREE.Vector3();
return function(t, dt) {
if (!this.data.target) return;
const target = this.data.target.getObject3D("mesh");
const position = target.getWorldPosition(tmpv);
this.el.object3D.position.lerp(tmpv, 0.5)
}
})()
})
</script>
<a-scene>
<!-- camera -->
<a-entity follow-box="target: #player" look-controls>
<a-entity camera position="0 1.6 2"></a-entity>
</a-entity>
<a-entity id="player" gltf-model="./scene.gltf" wasd-controls="speed: 35" ></a-entity>
</a-scene>
我正在使用 A 帧 (https://aframe.io) 创建一个虚拟现实场景,我想知道如何为 gltf 模型制作动画以始终跟随相机。例如,我想使用 A 帧的动画 属性 并定位我的模型,以便它始终跟随玩家。如果玩家向前移动 10 米,gltf 将动画向前移动 10 space。如果玩家向左移动 10spaces,无论玩家移动到哪里,摄像机都会跟随玩家。我想让 gltf 模型始终跟随相机。如何才能做到这一点?我的 gltf 模型代码:
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<a-scene>
<a-gltf-model class="cube" mixin="cube" animation=' property: position; dur: 2500; from: 0 2.3 -1; to: 0 2.5 -1; dir: alternate; autoplay: true; easing: linear; loop: true;' src="https://cdn.glitch.com/bb5471f0-16f5-4309-8c7c-52310dc4ff58%2FRobotfr.glb?v=1625527911166" position="0 2.3 -1"scale="1.2 1.2 1.2" speech-command__show="command: assistant; type: attribute; attribute: visible; value: true;"speech-command__hide="command: hide; type: attribute; attribute: visible; value: false;"></a-gltf-model>
</a-scene>
其实你问的是相机运动的第三人称视角相关的问题。这可以通过重新设置相机的父级轻松完成,并且您需要为相机添加一些偏移量,以便它始终看起来在相机前面
<a-camera>
<!-- The object with the same transform as the camera + some offset -->
<a-entity gltf-model="./scene.gltf" position="0 0 -0.5"></a-entity>
</a-camera>
如果这不起作用,请尝试创建和使用这样的组件
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-orbit-controls@1.2.0/dist/aframe-orbit-controls.min.js"></script>
<script>
AFRAME.registerComponent("follow-box", {
schema: {
target: {type: "selector"}
},
tick: (function() {
const tmpv = new THREE.Vector3();
return function(t, dt) {
if (!this.data.target) return;
const target = this.data.target.getObject3D("mesh");
const position = target.getWorldPosition(tmpv);
this.el.object3D.position.lerp(tmpv, 0.5)
}
})()
})
</script>
<a-scene>
<!-- camera -->
<a-entity follow-box="target: #player" look-controls>
<a-entity camera position="0 1.6 2"></a-entity>
</a-entity>
<a-entity id="player" gltf-model="./scene.gltf" wasd-controls="speed: 35" ></a-entity>
</a-scene>