I am using aframe physics extra component and trying to detect collision between two static bodies.
Here is my codepen - https://codepen.io/nirajupadhyay11/pen/gQraNq
However, I am not sure, why it is not working.
Here is the code -
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-animation-component@^4.1.2/dist/aframe-animation-component.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-physics-system/v3.1.2/dist/aframe-physics-system.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/aframe-physics-extras.min.js"></script>
<a-scene physics="gravity: 0">
<a-entity id='ball' position="0 1 -3" material="color:green;" geometry="primitive:sphere; radius: 1;" static-body physics-collider="ignoreSleep: true" animation="property: position; dur: 1500; easing: linear; to: 5 1 -3; dir:alternate; easing: easeInSine; loop:true">
</a-entity>
<a-plane color='grey' static-body rotation="-90 0 0" width="100" height="100"></a-plane>
<a-entity id='ball2' position="3 1 -3" material="color:red;" geometry="primitive:sphere; radius: 1;" static-body physics-collider="ignoreSleep: true"></a-entity>
</a-scene>
Could someone please help?
It seems to be working. The
physics-collider
provides an eventcollisions
which is emitted when both static bodies collide with each other.If you add an event listener
Check it out here.
If you expect an actual collision where one of the spheres fly away, then set
The
ignoreSleep
attribute is a flag responsible for waking up sleeping bodies (docs)