# A question on how applyForce work

To create a smooth acceleration on a spaceship, I use the applyForce function in every call of the “scene.registerAfterRender” loop, then I find a confusing decline on the LinearVelocity of the physicsImpostor.
I console.log() the “physicsImpostor.getLinearVelocity()” in each second here(the PhysicsImpostor’s mass and the force on z axis are both 1):
e {x: 0, y: -1.7879269573660925e-16, z: 0.9125334900243433}
e {x: 0, y: -2.0474306752575292e-16, z: 1.898483115518114} 0.9859496254937709
e {x: 0, y: 7.687377465365088e-17, z: 2.793606566177473} 0.8951234506593588
e {x: 0, y: 9.017056831196015e-16, z: 3.7767822344174657}
e {x: 0, y: 2.254228929525085e-15, z: 4.654680743052351}
e {x: 0, y: 4.594690234244627e-15, z: 5.6189370724315015}
e {x: 0, y: 7.730882187086167e-15, z: 6.511102152418256}
e {x: 0, y: 1.226615830650276e-14, z: 7.456486442117993}
e {x: 0, y: 1.7859625194924394e-14, z: 8.346461686068256}
e {x: 0, y: 2.4448979779180875e-14, z: 9.182453949402253}
e {x: 0, y: 3.336708286547252e-14, z: 10.100681766516667}
e {x: 0, y: 4.336647649617383e-14, z: 10.950259590319394}
e {x: 0, y: 5.599786948828297e-14, z: 11.850516219409066}
e {x: 0, y: 7.077403207272746e-14, z: 12.74162100466624} 0.8911047852571734
e {x: 0, y: 8.754497849525879e-14, z: 13.609279755013596} 0.8676587503473563
e {x: 0, y: 1.0565950915960372e-13, z: 14.425517535689757} 0.8162377806761612
e {x: 0, y: 1.2715472937687262e-13, z: 15.276337320726881} 0.8508197850371246

As you can see,the force’s acceleration effect become weaker and weaker，After a long time the LinearVelocity will infinite proximity 100.
I had tried CannonJSPlugin and AmmoJSPlugin,both of them has the same problem,could I find a way to handle it?

Calling @Cedric to the rescue

Hi @ljzc002

If the linear velocity declines when you don’t apply forces, it might be related to your damping value or the friction value if the impostor is in contact with some other objects, like a ground.
Can you set the damping value to 0 and see how it goes?

https://doc.babylonjs.com/api/interfaces/babylon.physicsimpostorparameters#damping

As it’s a spaceship in a void space,there are not any other objects in contact with it.And I had tried to set different friction for the physicsImpostor,it didn’t make any difference.
After you reply,I set the damping value to 0 like this:

ship.physicsImpostor = new BABYLON.PhysicsImpostor(ship, BABYLON.PhysicsImpostor.BoxImpostor
, { mass: 1, restitution: 0.0005 ,friction:1,damping:0}, scene);
ship.physicsImpostor.damping=0;

But the linear velocity declines still exist.

I post the spaceship demo to github: 三种物理引擎的加速度效果对比测试 .The physicsEngine is enabled in the initScene() function of the SpaceTest2.js file,the physicsImpostor is created in the initObj() function,the console.log() is in the initLoop() function,and the applyForce() is in the end of the Rocket2.js file.
Looking forward to the answer to this question.

1 Like

Hi L

``````scene.onReadyObservable.add(function() {   // wait for scene-ready
ship.physicsImpostor.physicsBody.linearDamping = 0; // translation damping
ship.physicsImpostor.physicsBody.angularDamping = 0;  // rotation damping, if wanted
});
``````

Should work. Most people put a code-block like this… near the end of their code. It doesn’t matter, really. It can go anywhere. CannonJS-ONLY… for THIS method. AmmoJS uses a completely different method, and OimoJS has no damping settings, as far as I know.

AmmoJS bodies DO have damping… bullet3/btRigidBody.h at master · bulletphysics/bullet3 · GitHub … but I have no idea how to set them… from JS. Few people “go native” with AmmoJS. What I mean by “native”… is reaching deep-down into the physics engine… to set/read properties, and run functions.

In the above CannonJS example… we went native, but it was easier… because of the way CannonJS is designed. AmmoJS… more difficult. A web search for ‘Bullet physics setDamping’ might be useful… for learning about AmmoJS damping.

Back to CannonJS stuff:

``````ship.physicsImpostor.physicsBody.linearDamping = 0
\               \
BJS object         \
CannonJS object
``````

When we use physicsImpostor, THAT is at the BabylonJS level, so NOT “CannonJS native” area. physicsImpostor is a BabylonJS-created object.

When we reach BEYOND physicsImpostor. and down-to physicsBody, THAT is “CannonJS native” area. physicsBody is a CannonJS-created object.

For AmmoJS, I am not experienced at all with “native”… but perhaps others, are. In another thread, we once talked about AmmoJS (BulletEngine) native stuff. I don’t know if anything can be learned, there… but here is the thread. https://forum.babylonjs.com/t/ammo-js-collision-response-and-filtering/

1 Like

Thanks very much,it really work on CannonJS !
Inspired by you，I find the function to set the AmmoJS native damping,it’s:
ship.physicsImpostor.physicsBody.setDamping(0,0);Thank you again.

1 Like

COOL! Thanks!