我正在使用PhysicsJS制作 2D 轮盘赌球旋转动画。
到目前为止,我已经实现了以下内容:
- 使用约束以使球不会“飞走”:
rigidConstraints.distanceConstraint( wheel, ball, 1 );
- 使用阻力来减慢球的速度:
world.add(Physics.integrator('verlet', { drag: 0.9 }));
- 使轮子吸引球,因此当阻力使球减速足够时,它会朝它下落
我的问题:
- 如何逐渐减慢球的旋转速度?
我已经有很高的drag
价值了,但它看起来并没有做任何事情 - 我如何使对车轮的吸引力起作用?
距离限制应该防止球逃跑,而不是靠近轮子。 - 为什么
angularVelocity: -0.005
在车轮上根本不起作用?
我的代码,也在JSfiddle
Physics(function (world) {
var viewWidth = window.innerWidth
,viewHeight = window.innerHeight
,renderer
;
world.add(Physics.integrator('verlet', {
drag: 0.9
}));
var rigidConstraints = Physics.behavior('verlet-constraints', {
iterations: 10
});
// create a renderer
renderer = Physics.renderer('canvas', {
el: 'viewport'
,width: viewWidth
,height: viewHeight
});
// add the renderer
world.add(renderer);
// render on each step
world.on('step', function () {
world.render();
});
// create some bodies
var ball = Physics.body('circle', {
x: viewWidth / 2
,y: viewHeight / 2 - 300
,vx: -0.05
,mass: 0.1
,radius: 10
,cof: 0.99
,styles: {
fillStyle: '#cb4b16'
,angleIndicator: '#72240d'
}
})
var wheel = Physics.body('circle', {
x: viewWidth / 2
,y: viewHeight / 2
,angularVelocity: -0.005
,radius: 100
,mass: 100
,restitution: 0.35
// ,cof: 0.99
,styles: {
fillStyle: '#6c71c4'
,angleIndicator: '#3b3e6b'
}
,treatment: "static"
});
world.add(ball);
world.add(wheel);
rigidConstraints.distanceConstraint( wheel, ball, 1 );
world.add( rigidConstraints );
// add things to the world
world.add([
Physics.behavior('interactive', { el: renderer.el })
,Physics.behavior('newtonian', { strength: 5 })
,Physics.behavior('body-impulse-response')
,Physics.behavior('body-collision-detection')
,Physics.behavior('sweep-prune')
]);
// subscribe to ticker to advance the simulation
Physics.util.ticker.on(function( time ) {
world.step( time );
});
// start the ticker
Physics.util.ticker.start();
});