Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling gravity in Matter.js

Is there any way to disable gravity in Matter.js? I want my objects (bodies) to keep their physical abilities (like reaction to collision, restitution, friction etc), but I'd like to prevent the reaction to device's gyro and orientation change.

like image 355
Igal Avatar asked Apr 06 '15 06:04

Igal


2 Answers

Try

engine.world.gravity.y = 0;

where engine is your engine instance.

like image 63
sowee15 Avatar answered Oct 22 '22 04:10

sowee15


You just need to add this to your config:

physics: {
    default: "matter",
    matter: {
        gravity: {x: 0, y: 0},
        // ^^^^^^^^^^^^^^^^^^^
    }
}
like image 37
Alexander Avatar answered Oct 22 '22 06:10

Alexander