2017-07-18 3 views
3

私は自分の世界にボールと2つのまっすぐな垂直面を持っています。なぜ私の円はある角度で真っ直ぐな表面から跳ね返っていますか?

私はボールに力を加えると、私はそれが一直線にとどまると思っていますが、ある角度で跳ね返っているように見えます。

フィドル: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 }); 
+1

ボールの摩擦をオフにしてそれを修正します。 –

+0

ボールにスピンがありますか? –

+0

私はプールボールをシミュレートしようとしていますが、私は布とテーブルの間に摩擦が必要でした。 –

答えて

4

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

を設定することができます。しかし、今あなたは、壁に触れてボールを取得するためにもう少し力を適用する必要があります。私はちょうどそれを振った.06

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

.6の先頭のゼロを残すためにあなたを呪う。 :P –

+2

intertia vs inertia –

+0

それはまだ隙間が無限に設定された奇妙な角度で跳ね返ります - https://jsfiddle.net/zvjvvzeL/22/ –

関連する問題