我想让一个文本实体落入一个场景。 dynamic-body
适用于其他元素(球体,立方体等),但不适用于a-text
。
这是我的故障:
答案 0 :(得分:2)
dynamic-body
中的自动形状检测无法处理文本。您可以手动应用物理体形状。
<!DOCTYPE html>
<html>
<head>
<title>The text shall fall. - A-Frame</title>
<meta name="description" content="The text shall fall.">
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<script src="//cdn.rawgit.com/donmccurdy/aframe-physics-system/v2.1.0/dist/aframe-physics-system.min.js"></script>
<script>
window.onload = () => {
const text = document.querySelector('a-text')
// Cannon boxes use 'halfExtents', side length / 2
const shape = new CANNON.Box(new CANNON.Vec3(0.5, 0.1, 0.5))
// body may or may not be ready when onload occurs
if (text.body) {
text.body.addShape(shape)
} else {
text.addEventListener('body-loaded', () => text.body.addShape(shape))
}
}
</script>
</head>
<body>
<a-scene>
<!-- "shape:none" to disable auto detection. Required if combining text and geometry in same entity tree -->
<a-text dynamic-body="shape:none" position="-1 2 -3" value="Cylinder falls, this does too." height="1.5" color="#FFC65D" ></a-text>
<a-cylinder dynamic-body position="1 5 -3" rotation="12 0 0" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane static-body position="0 0 -4" rotation="-90 0 0" width="14" height="14" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
</body>
</html>
答案 1 :(得分:2)
尝试将文字放在一个薄盒子上。
<a-entity geometry="primitive: box; depth: 0.01" text="value: HEY" dynamic-body>