【问题标题】:Why is my circle bouncing off straight surface at an angle?为什么我的圆圈会以一定角度从直线表面反弹?
【发布时间】:2017-07-18 15:08:33
【问题描述】:

我的世界中有一个球和两个垂直的直面。

当我对球施加力时,我希望它保持在一条直线上,但它似乎会以一定角度反弹。

小提琴:https://jsfiddle.net/zvjvvzeL/11/

var Engine = Matter.Engine,
        Render = Matter.Render,
        World = Matter.World,
        Bodies = Matter.Bodies,
        Body = Matter.Body,
        Vector = Matter.Vector,
        Events = Matter.Events;

    // create an engine
    var engine = Engine.create();

    var canvas = document.getElementById('canvas');

    engine.world.gravity.y = 0; // gravity not needed in this app

    // create a renderer
    var render = Render.create({
        element: document.body,
        canvas: canvas,
        engine: engine,
        options: {wireframes: true}
    });

    var ball_0 = Bodies.circle(100, 150, 11, {
        density: 0.04,
        frictionAir: 0.06,
        restitution: 0.8,
        friction: 0.3
    });

    var cushion_left = Bodies.rectangle(34, 160, 100, 208, { isStatic: true });
    var cushion_right = Bodies.rectangle(492, 160, 100, 208, { isStatic: true });

    // add all of the bodies to the world
    World.add(engine.world, [cushion_left, cushion_right, ball_0]);

    render.options.height = 300;
    canvas.height = 300;
    Engine.run(engine);
    Render.run(render);

    Body.applyForce(ball_0, { x: 0, y: 0 }, { x: 0.5, y: 0 });

【问题讨论】:

  • 关闭球上的摩擦可以解决问题。
  • 球有旋转吗?
  • 没有旋转我正在尝试模拟一个台球,我想要布料和桌子之间的摩擦。

标签: javascript physics matter.js


【解决方案1】:

对 MatterJS 不太熟悉,但看起来球默认应用了角度旋转。我认为这只会影响像您构建的那样的封闭系统。

也许从长远来看你会想要它,但现在你可以设置intertia : Infinity

var ball_0 = Bodies.circle(100, 150, 11, {
    density: 0.04,
    frictionAir: 0.06,
    restitution: 0.8,
    friction: 0.3,
    inertia : Infinity
});

但现在你还必须稍微用力一点,才能让球接触到墙壁。我刚把它调到 0.6

Body.applyForce(ball_0, { x: 0, y: 0 }, { x: .6, y: 0 });

【讨论】:

  • 诅咒你把前导零从 .6 中去掉! :P
  • 惯性与惯性
  • 它仍然以奇怪的角度反弹,intertia 设置为无穷大 - jsfiddle.net/zvjvvzeL/22
  • 我的错。我在我的例子中拼错了惯性,你似乎把它抄过来了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-10
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 2020-06-14
相关资源
最近更新 更多