Skip to content

Commit 2b20c8b

Browse files
committed
Add matter component for inertia - useful for platformers
1 parent 08df6b4 commit 2b20c8b

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/physics/matter-js/MatterImage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var MatterImage = new Class({
1616
Components.Force,
1717
Components.Friction,
1818
Components.Gravity,
19+
Components.Inertia,
1920
Components.Mass,
2021
Components.Sensor,
2122
Components.SetBody,

src/physics/matter-js/MatterSprite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var MatterSprite = new Class({
1717
Components.Force,
1818
Components.Friction,
1919
Components.Gravity,
20+
Components.Inertia,
2021
Components.Mass,
2122
Components.Sensor,
2223
Components.SetBody,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var Body = require('../lib/body/Body');
2+
3+
var Inertia = {
4+
5+
setInertia: function (value)
6+
{
7+
Body.setInertia(this.body, value);
8+
9+
return this;
10+
},
11+
12+
// Useful to prevent rotation on body, e.g. for player in a platformer
13+
setMaxInertia: function ()
14+
{
15+
Body.setInertia(this.body, Number.POSITIVE_INFINITY);
16+
17+
return this;
18+
}
19+
};
20+
21+
module.exports = Inertia;

src/physics/matter-js/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
Force: require('./Force'),
88
Friction: require('./Friction'),
99
Gravity: require('./Gravity'),
10+
Inertia: require('./Inertia'),
1011
Mass: require('./Mass'),
1112
Static: require('./Static'),
1213
Sensor: require('./Sensor'),

0 commit comments

Comments
 (0)