How to change the gravity in Matter Js Engine

• 1 min read

Here the way to change the gravity value at runtime in a Matter.js engine instance:

// suppose this engine
var engine = Engine.create()

// engine.gravity contains the default gravity value
/*
gravity: {
	x: 0,
	y: 1,
	scale: 0.001
},
*/

// change it at runtime:
engine.gravity.y = 0.3

Learned from the source code here.