我使用“A帧物理系统”(https://github.com/donmccurdy/aframe-physics-system)在A帧中创建了一个场景:
<!DOCTYPE>
<html>
<head>
<script src="aframe.min.js"></script>
<script src="aframe-extras.min.js"></script>
<script src="aframe-physics-system-master/dist/aframe-physics-system.min.js"></script>
</head>
<a-scene id="myscene" physics>
<!--CAMERA-->
<a-entity camera="userHeight: 1.6" look-controls></a-entity>
<!--BALL1-->
<a-sphere color="red" radius="0.3" position="5 5 5" dynamic-body></a-sphere>
<!--BALL2-->
<a-sphere color="green" radius="0.3" position="6 5 5" dynamic-body></a-sphere>
<!--GROUND-->
<a-plane id="ground" height="200" width="200" rotation="-90 0 0" position="0 0 0" metalness="0" roughness="1" static-body></a-plane>
</a-scene>
</body>
</html>场景由两个球体和一个平面组成。当一个球撞上飞机时,我想让它弹得比其他球多。我从文档中了解到,我们可以通过以下方法改变整个场景的摩擦和复原等属性:
<a-scene physics="friction: 0.1; restitution: 0.5">
<!-- ... -->
</a-scene>但我想要不同领域的摩擦和恢复价值。如果有可能,请让我知道。提前感谢!
发布于 2017-06-16 16:54:53
根据物理构件文档:通过CANNON.js JavaScript API为不同对象指定不同的碰撞行为。
对于自定义行为,您需要深入到Cannon.js文档并找到所需的方法和类。尽管如此,实现定制材料的方式如下:
有了这些,您可以首先执行以下操作:
var world = $('a-scene')[0].systems.physics.world;var firstMaterial = new CANNON.Material("firstMaterial"); var secondMaterial = new CANNON.Material("secondMaterial");$('#cannon')[0].body.material=firstMaterial; $('floor')[0].body.material=secondMaterial;var secondCM = new CANNON.ContactMaterial(firstMaterial,secondMaterial, [restitution = 2]); world.addContactMaterial(secondCM);中这里你可以找到一把有用的小提琴。
https://stackoverflow.com/questions/44590227
复制相似问题