我是physicsjs的新手,为了熟悉这个库,我正在创建一些测试模拟。
我想模拟在屏幕上滑动的多个盒子,它们都经历了不同程度的摩擦。到目前为止,我有3个框,从屏幕的左边开始,都有一个pos xvel。我不确定将摩擦力添加到模拟中的最佳方法是什么。所有3个盒子都不应该受到摩擦的相同影响。因此,我需要一些方法来应用一个通用的摩擦力算法到所有的盒子,但是摩擦力的大小需要取决于它当前作用于哪个盒子。
发布于 2014-05-16 00:19:07
摩擦是内置的(但它不是最好的算法)。
只需使用:
Physics.body('rectangle', {
width: 40,
height: 40,
cof: 0.5, // <-- change the friction. range [0, 1]
x: ...
...
});发布于 2016-02-25 23:39:10
空空间摩擦可以通过这种方式来实现。不管球在做什么,它都在减速。
它监听tick事件,然后在每次更新时通过摩擦力的大小来降低速度。
```javascriptfunction applyFriction(obj,friction) {
// invert it so that 0.1 friction is a multiplication of 0.9 to x.// it makes more sense to apply 0.1 as friction that way.var value = 1 - friction;obj.state.vel.set(obj.state.vel.x * value, obj.state.vel.y * value);}
//订阅滚动条
Physics.util.ticker.on(函数(时间){
applyFriction(ball, 0.1);// apply friction to the ball.world.step(time);});
//启动报价器
Physics.util.ticker.start();
https://stackoverflow.com/questions/23666783
复制相似问题