-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttract.js
40 lines (32 loc) · 1.15 KB
/
Attract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Applies an attract force towards centerOfMass
export default class Attract {
static RequiresUpdate = true;
static RunInteraction(scn, options) {
let attraction = 0.001;
let iteration = 0;
if (Object.keys(options).length > 0){
({ iteration, attraction } = options);
}
if (iteration === 0 || iteration == null) {
const attract = (bodyA, bodyB) => {
const force = new scn.Phaser.Math.Vector2(bodyA.position).subtract(bodyB.position);
return {
x: force.x * attraction,
y: force.y * attraction
};
}
for (let i = 0; i < scn.flubbers.length; i++) {
const flubberBody = scn.flubbers[i];
if (flubberBody === scn.centerOfMass) {
flubberBody.plugin = {
attractors: [
attract
]
}
continue;
}
}
} else {
}
}
}