2

I can't change the restitution (bounciness) either globally or on a per mesh basis when using ammo physics.

So far I've included the libraries:

<script src="https://mixedreality.mozilla.org/ammo.js/builds/ammo.wasm.js"></script>
<script src = "./scripts/aframe-physics-system.js"></script>

Added it to the scene:

physics="driver: ammo; debug: true;"

I tried defining restitution and friction there, but this has no effect - I believe this works when using cannon.

Added the dynamic-body to the model:

<a-entity gltf-model="#egg0" id="egg" position="2 15 -5" ammo-body="type: dynamic;" ammo-shape="type: sphere; fit: manual; sphereRadius: 1.3;"></a-entity>

Really not sure what to do at this point I've tried to get and set with things I've found around the web, but there doesn't seem to be many examples using ammo and aframe together :(

    el.body.setFriction(1);
    el.body.setRestitution(0.8);
    el.body.setDamping(0.2, 0.2);
    el.body.getRestitution();

These do nothing, but also no errors appear in the log?

If there's a way to log out the ammo properties at least I'd have a way to use trial and error, but can't even get to those numbers!

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

1

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>
mackbjon
  • 11
  • 1
0

Any progress on this?

Checkout https://github.com/kripken/ammo.js/blob/master/ammo.idl to see if you're calling the correct functions. If you console.log the el.body what are you getting?

If el.body isn't working try el.components[ "ammo-body" ].body to obtain reference to the body.

You may also have to use body.upcast to obtain the btCollisionObject and then call setFriction on that

hayden_g
  • 47
  • 4