wmurphyrd / aframe-physics-extras

🔧Cannon API interface components the A-Frame Physics System
MIT License
27 stars 8 forks source link

Using sleepy makes the dynamic body stop and shake continuously #10

Closed nirajupadhyay11 closed 6 years ago

nirajupadhyay11 commented 6 years ago

Hi,

I am creating a dynamic body this way -

const el = document.createElement('a-entity')
        el.setAttribute('id', this.data.id);
        el.setAttribute('gltf-model', this.data.src)
        const offset = new THREE.Vector3(rg.real(-jx,jx), rg.real(0.5,jy), rg.real(-jz,jz));
        el.setAttribute('position', center.clone().add(offset));
        el.object3D.scale.set(0.01,0.01,0.01);
        el.setAttribute('dynamic-body', 'shape:sphere; sphereRadius: .3; mass: 5');
        el.setAttribute('velocity', '0 0 23');
        el.setAttribute('sleepy', true);
        console.log(el);
        sceneEl.appendChild(el);

But, the body becomes very slow, falls to the ground and starts to shake.

If I don't use "sleepy" then the body moves quickly, does not stop after collision and shaking happens in this case as well.

I am looking for a solution to make the body move quickly before the collision, come to a stop after a collision and the shaking needs to stop ( I realize that the shaking is independent of using the sleepy component)

I have spend countless hours trying to solve this. Could you please help?

Thanks, Niraj

wmurphyrd commented 6 years ago

Sleep has a default setting to dampen movement that is causing the slowdown.

Change it by decreasing the linearDamping and angularDamping properties.

The shaking I suspect is caused by using the velocity component on a dynamic body. I would try using the applyImpulse/applyLocalImpulse Cannon body methods instead. See example here: https://github.com/quinn-madson/ars-attacks/blob/master/server/static/js/projectile.js