如何使用 Aframe 获得模型的第三人称视角?
我希望我的 A 框相机位于模型后面并充当 TPP。我想要一个模型与相机同步,并在相机移动的地方旋转和移动,但如果相机向上和向下指向,它不应该移动,它不应该看起来像模型被卡在相机上。
<html>
<head>
<script src="https://aframe.io/releases/0.7.1/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v3.13.1/dist/aframe-extras.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/aframe-physics-components.min.js"></script>
<script src="https://unpkg.com/aframe-event-set-component@^4.0.0/dist/aframe-event-set-component.min.js"></script>
<script src="https://unpkg.com/super-hands@^3.0.1/dist/super-hands.min.js"></script>
</head>
<body>
<a-scene physics="gravity: -9.8; restitution: 0.7;" antialias="true">
<a-assets>
<img id="ground-grass" src="grass.jpg" />
</a-assets>
<a-entity universal-controls="" camera kinematic-body=""
position="-2.9021956210846644 1.5405810531492952 -3.927244596410301"></a-entity>
<a-plane src="#ground-grass" scale="50 50 1" repeat=" 5 5 1" rotation="-90 0 0" static-body></a-plane>
<a-box color="#AA0000" scale="2 2 2" position="-2.5 0.5 -7.5" static-body></a-box>
</a-scene>
</body>
</html>
如果我移动相机,盒子也应该移动。 输出图像
I want my A-frame camera to be behind the model and work as a TPP. I want a model to sync with the camera and rotate and move where ever the camera is moving but it should not move if the camera is pointing up and down it should not look like the model is stuck on the camera.
<html>
<head>
<script src="https://aframe.io/releases/0.7.1/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v3.13.1/dist/aframe-extras.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/aframe-physics-components.min.js"></script>
<script src="https://unpkg.com/aframe-event-set-component@^4.0.0/dist/aframe-event-set-component.min.js"></script>
<script src="https://unpkg.com/super-hands@^3.0.1/dist/super-hands.min.js"></script>
</head>
<body>
<a-scene physics="gravity: -9.8; restitution: 0.7;" antialias="true">
<a-assets>
<img id="ground-grass" src="grass.jpg" />
</a-assets>
<a-entity universal-controls="" camera kinematic-body=""
position="-2.9021956210846644 1.5405810531492952 -3.927244596410301"></a-entity>
<a-plane src="#ground-grass" scale="50 50 1" repeat=" 5 5 1" rotation="-90 0 0" static-body></a-plane>
<a-box color="#AA0000" scale="2 2 2" position="-2.5 0.5 -7.5" static-body></a-box>
</a-scene>
</body>
</html>
If I move the camera the box should also move.
Output image
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是简单地重新调整父级:
一个更复杂但灵活的解决方案是使用 JavaScript 创建控制器。假设我们想要:
我们可以用这样的组件来做到这一点:
这是一个故障 它在 aframe 网络中工作
最好的方法是重新使用 orbit-controls,但据我所知,如果没有一些自定义,它们将无法与 wasd 控件一起使用
The easiest way would be simple reparenting:
A more complex, but flexible solution, would be creating a controller with javascript. Lets say we want to:
we could do it with a component like this:
Here's a glitch of it working in aframe networked
The best way would be to re-use the orbit-controls, but afaik they won't work with wasd controls without some customization