我已经在一个静态框中创建了一个动态圆(四个静态墙组成一个框)。对这个世界施加了负重力。
现在的效果是圆形身体应该从内壁反弹,并最终稳定下来。
使用restituion=1,我得到的效果是:弹离墙壁不断增加,它永远不会停止。
我做错了什么?我以为resitution=1的意思是不确定的反弹(相同距离),但这里的反弹距离是逐渐增加的。
// create ground (box-type object)
function createGround(x, y, width, height, rotation) {
// box shape definition
var groundSd = new b2BoxDef();
groundSd.extents.Set(width, height);
groundSd.restitution = 0.0;
var groundBd = new b2BodyDef();
groundBd.AddShape(groundSd);
groundBd.position.Set(x, y);
groundBd.rotation = rotation * Math.PI / 180;
return world.CreateBody(groundBd);
}
function createCircleAt(x, y, r) {
var boxSd = new b2CircleDef();
boxSd.density = 1.0;
boxSd.friction = 1.0;
boxSd.restitution = 1.0;
boxSd.radius = r;
// add to world as shape
var boxBd = new b2BodyDef();
boxBd.AddShape(boxSd);
boxBd.position.Set(x,y);
return world.CreateBody(boxBd);
}使用box2d.js
发布于 2013-09-13 18:21:45
Box2d不会给出精确的模拟。将恢复率设置为1.0只会使物理效果看起来“足够接近”。
发布于 2013-09-18 05:16:26
我猜这取决于你的墙的修复价值。球在有它自己的“行为”的墙上反弹,如果我没记错的话,它会计算2之间的比率。你有没有试着改变墙的恢复值?
https://stackoverflow.com/questions/18743429
复制相似问题