BulletPhysics(ammo.js)-您将如何对物体施加力? [英] BulletPhysics (ammo.js) - How would you go about applying force to an object?

查看:481
本文介绍了BulletPhysics(ammo.js)-您将如何对物体施加力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了澄清- ammo.js 是使用mscripten的Bullet Physics的移植

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) 甚至不移动块-只是阻止重力作用在块上!
applyImpulse([0,0,200000],[0,0,0])绝对没有任何作用。

applyForce([0,0,200000],[0,0,0])绝对没有任何作用。

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.

推荐答案

由于ammo.js是一个脚本端口,因此您必须使用其本机数据类型与之通信...

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

设置您需要的速度body.setLinearVelocity(new Ammo.btVector3(1,0,0));

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

applyForce和applyImpulse都一样。

Same goes for applyForce and applyImpulse.

在我的代码中,我通常制作一组临时的btVector3s,并在整个文件中使用它们,以减少分配和垃圾回收的开销。.

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);
}

祝你好运:D

这篇关于BulletPhysics(ammo.js)-您将如何对物体施加力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆