当相机靠近球体时,我试图显示一些文本。这个想法是,当用户看到球体移得更近时,就会显示文本,比如说“你好”。但现在我只知道如何使用实体添加固定位置的文本,我不知道如何检测相机和球体之间的距离,并在用户看到球体靠近时显示文本。现在这是我的代码:
<html>
<head>
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
</head>
<body>
<a-scene>
<a-sphere position="0 0 0" perspective="true" radius="1.5" color="#aaa" id="sphere1"></a-sphere>
<a-entity position="4.5 2 0" text="width: 10; color: white; value: Hello"></a-entity>
<a-sky color="#000"></a-sky>
<a-entity class="camwrap" position="0 0 0">
<a-camera look-controls wasd-controls="fly:true acceleration:1" near="1" position="0 0 20" user-height="0" fov="60">
</a-camera>
</a-entity>
</a-scene>
<script>
const cam = document.querySelector("a-camera");
setTimeout(function() {
cam.components["wasd-controls"].keys["KeyW"] = true;
}, 1000);
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?