最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - A-FRAME and collision detection between two tubes - Stack Overflow

programmeradmin1浏览0评论

How do you detect a collision between 2 tubes?

Normal usage of collision libraries doesn't work for tubes. As far as I know, these libraries use cannon.js. And cannon.js doesn't have tube shape.

How can I achieve collision between two tubes?

<script src=".5.0/aframe.min.js"></script>
<script src=".js"></script>
<script src=".js"></script>
<script src=".0.1/dist/aframe-physics-system.min.js"></script>
<script src=".js"></script>


<a-scene physics="gravity: -9.8">
  <a-entity id="objId-1_path" parametric-curve="xyzFunctions: (1 - t) * (1 - t) * (1 - t) * (9.866869455043389) + 3 * (1 - t) * (1 - t) * t * (9.296747637261328) + 3 * (1 - t) * t * t * (-5.081858662029424) + t * t * t * (0), (1 - t) * (1 - t) * (1 - t) * (3.448332289736946) + 3 * (1 - t) * (1 - t) * t * (3.342113628013926) + 3 * (1 - t) * t * t * (0) + t * t * t * (0), (1 - t) * (1 - t) * (1 - t) * (1.1538943718962802) + 3 * (1 - t) * (1 - t) * t * (2.528342153338074) + 3 * (1 - t) * t * t * (4.713655696327929) + t * t * t * (0); tRange: 0, 1;"></a-entity>

  <a-entity id="objId-2_path" parametric-curve="xyzFunctions: (1 - t) * (1 - t) * (1 - t) * (-8.255694973427389) + 3 * (1 - t) * (1 - t) * t * (-8.176697626601747) + 3 * (1 - t) * t * t * (-5.081858662029424) + t * t * t * (0), (1 - t) * (1 - t) * (1 - t) * (5.352404450414396) + 3 * (1 - t) * (1 - t) * t * (5.592985477997834) + 3 * (1 - t) * t * t * (0) + t * t * t * (0), (1 - t) * (1 - t) * (1 - t) * (-7.1757925398181355) + 3 * (1 - t) * (1 - t) * t * (-8.11555796776703) + 3 * (1 - t) * t * t * (4.713655696327929) + t * t * t * (0); tRange: 0, 1;"></a-entity>

  <!-- Objekti s fizičkim svojstvima -->
  <a-entity id="one" position="0 0 -4" class="orange" tube-geometry="curveData: #objId-1_path; type: parametric-curve; tubeSegments: 100; radius: 0.43395090103149414; tubeColor: orange; opacity: 1;" dynamic-body  material="side: double"></a-entity>
  <a-entity id="two" position="0 0 -3" class="orange" tube-geometry="curveData: #objId-2_path; type: parametric-curve; tubeSegments: 100; radius: 0.43395090103149414; tubeColor: red; opacity: 1;" dynamic-body  material="side: double"></a-entity>

  <a-sky color="#ECECEC"></a-sky>
</a-scene> 

<script>
  // Detekcija sudara koristeći aframe-physics-system
  document.querySelector("#one").addEventListener("collide", function (e) {
    console.log('Objekt 1 je u sudaru s: ', e.detail.body.el);
  });

  document.querySelector("#two").addEventListener("collide", function (e) {
    console.log('Objekt 2 je u sudaru s: ', e.detail.body.el);
  });
</script> 
发布评论

评论列表(0)

  1. 暂无评论