2

To clarify - ammo.js is a port of Bullet Physics using mscripten

I have a character (essentially a block) that needs to be pushed with force. I have tried (I think) all of the methods for forces but I still cannot move the block.

setVelocity(1,0,0) does not even move the block - it just stops gravity from acting on it! applyImpulse([0,0,200000],[0,0,0]) does absolutely nothing.
applyForce([0,0,200000],[0,0,0]) does absolutely nothing.

Reed
  • 14,703
  • 8
  • 66
  • 110
MineMan287
  • 55
  • 1
  • 6
  • For future reference, surround inline code with ` (the thing next to the number 1). – Reed Dec 19 '14 at 02:22

1 Answers1

4

Due to the fact that ammo.js is an emscripten port, you have to use its native datatypes to talk to it...

So for setting velocity you'd need to body.setLinearVelocity(new Ammo.btVector3(1,0,0));

Same goes for applyForce and applyImpulse.

In my code, I usually make a set of temporary btVector3s, and use them throughout the file, in order to reduce the overhead of allocation and garbage collection..

var tbv30 = new Ammo.btVector3();

function setBodyVelocity(body,x,y,z){
    tbv30.setValue(x,y,z);
    body.setLinearVelocity(tbv30);
}

good luck :D

manthrax
  • 4,918
  • 1
  • 17
  • 16
  • Not sure I follow, @Funkodebat ? – manthrax Nov 26 '18 at 13:48
  • well... assuming all you want to do is reuse the vector.. then you'd want `function doSomeStuff(body, x, y, z) { ... }` so you can actually use your own values instead of 10,0,0 every time. – dansch Nov 27 '18 at 00:07
  • 1
    Note for beginners: if body.setLinearVelocity() is not doing anything, the body might be deactivated. Call body.activate() before body.setLinearVelocity(). – Tom Jan 06 '22 at 23:02