javascript - BulletPhysics (ammo.js) - How would you go about applying force to an object? - Stack Overflow

To clarify - ammo.js is a port of Bullet Physics using mscriptenI have a character (essentially a block

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.

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.

Share Improve this question edited Dec 19, 2014 at 2:20 Reed 15k8 gold badges72 silver badges113 bronze badges asked Oct 26, 2014 at 12:34 MineMan287MineMan287 551 silver badge6 bronze badges 1
  • For future reference, surround inline code with ` (the thing next to the number 1). – Reed Commented Dec 19, 2014 at 2:22
Add a ment  | 

1 Answer 1

Reset to default 6

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745455334a4628460.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信