UNPKG

@c-frame/physx

Version:

Physics for A-Frame using Nvidia PhysX

48 lines (47 loc) 1.71 kB
<!DOCTYPE html> <html> <head> <title>Examples • TTL PhysX</title> <script src="https://aframe.io/releases/1.7.1/aframe.min.js"></script> <script src="../../dist/physx.js"></script> <link rel="stylesheet" href="../../styles.css"> <script> AFRAME.registerComponent('ttl', { schema: { time: {type: 'number', default: 100} }, init: function(){ this.ticks = 0; this.lifetime = this.data.time; }, tick: function(){ this.lifetime--; if(this.lifetime === 0){ // TTL has expired remove the entity this.el.sceneEl.removeChild(this.el); } } }); </script> </head> <body> <div class="text-overlay"> <p>The box disappears after 100 frames.</p> </div> <a class="code-link" target="_blank" href="https://github.com/c-frame/physx/blob/main/examples/ttl/index.html"> view code </a> <a-scene physx="autoLoad: true; delay: 100; useDefaultScene: false"> <a-box position="-1 3.5 -3" rotation="0 45 0" color="#4CC3D9" shadow physx-body ttl></a-box> <a-sphere position="0 3.75 -5" radius="1.25" color="#EF2D5E" shadow physx-body></a-sphere> <a-cylinder position="1 4.0 -3" radius="0.5" height="1.5" color="#FFC65D" shadow physx-body></a-cylinder> <!-- When using a plane with PhysX, the physics geometry is not modelled correctly - too wide so use a thin box instead--> <a-box position="0 -0.005 -4" rotation="-90 0 0" depth="0.01" width="4" height="4" color="#7BC8A4" shadow physx-body="type: static"></a-box> <a-sky color="#ECECEC"></a-sky> </a-scene> </body> </html>