n5ro / aframe-physics-system

Physics system for A-Frame VR, built on CANNON.js.
https://n5ro.github.io/aframe-physics-system/
MIT License
505 stars 136 forks source link

How can you change restitution when using aframe physics system with ammo.js #186

Open Jantu82 opened 3 years ago

Jantu82 commented 3 years ago

Is it possible to change the restitution (bounciness) somehow when using ammo.js with aframe physics system?

mackbjon commented 3 years ago

Restitution with ammo.js is zero by default which requires every object in collision to be given explicit value.

Example below uses a ball and floor:

AFRAME.registerComponent("do-something", {
        init: function () {
          var sceneEl = this.el;
          var floorEl = sceneEl.querySelector("#floor");
          var ballEl = sceneEl.querySelector("#ball");
          floorEl.body.setRestitution(0.9);
          ballEl.body.setRestitution(0.8);
        },
      });

<a-scene do-something>