【发布时间】:2021-11-17 15:04:38
【问题描述】:
我开始使用 Aframe 1.2.0 和 Ammo.js 制作游戏,因为 CANNON.js 支持将来可能会被弃用。
我有一个非常简单的起点 - 一个静态框 - 一个动态球体 - 单击球体以发射 - 它应该从盒子反弹,但它只是穿过它。我尝试将拍摄功能放入组件中,但发生了同样的事情。
此处出现故障 -> https://descriptive-truthful-sneezeweed.glitch.me
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta id="theme-color" name="theme-color" content="#ffffff">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
<script src="https://cdn.jsdelivr.net/npm/aframe-physics-system@4.0.1/dist/aframe-physics-system.min.js"></script>
</head>
<body>
<a-scene id="mainScene" vr-mode-ui="enabled: false" physics=" driver: ammo; debug: true; debugDrawMode: 1;"
device-orientation-permission-ui="enabled: false"
renderer='antialias: true; colorManagement: true; sortObjects: false; precision: high; logarithmicDepthBuffer: false; physicallyCorrectLights: false;'
raycaster="objects: .clickable"
cursor="fuse: false; rayOrigin: mouse">
<a-box id="backboard" position="0 2 -5" width="1" height="1" depth="0.2" ammo-body="type: static; emitCollisionEvents: true;" ammo-shape="type: box" material="color: tomato;"></a-box>
<a-sphere id="ball" position="0 0 -2" radius="0.15" ammo-shape="type: sphere; fit: manual; sphereRadius: 0.15;" material="color: cyan;"></a-sphere>
</a-scene>
<script>
$("#ball").addClass("clickable");
ball.addEventListener("click", shoot);
backboard.addEventListener("collidestart", function() {
console.log("HIT");
});
function shoot() {
ball.setAttribute("ammo-body","type: dynamic;");
const force = new Ammo.btVector3(0, 7, -3);
const pos = new Ammo.btVector3(ball.object3D.position.x, ball.object3D.position.y, ball.object3D.position.z);
ball.body.applyImpulse(force, pos);
Ammo.destroy(force);
Ammo.destroy(pos);
}
</script>
</body>
</html>
【问题讨论】:
标签: game-physics aframe ammo.js