admin管理员组文章数量:1425717
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.
- For future reference, surround inline code with ` (the thing next to the number 1). – Reed Commented Dec 19, 2014 at 2:22
1 Answer
Reset to default 6Due 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
本文标签: javascriptBulletPhysics (ammojs)How would you go about applying force to an objectStack Overflow
版权声明:本文标题:javascript - BulletPhysics (ammo.js) - How would you go about applying force to an object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745455334a2659076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论