-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipe-height.js
42 lines (34 loc) · 1.4 KB
/
pipe-height.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
41
42
import { Script } from 'playcanvas';
export class PipeHeight extends Script {
initialize() {
var app = this.app;
// this.pipe1 = app.root.findByName('Pipe 1');
// this.pipe2 = app.root.findByName('Pipe 2');
// this.pipe3 = app.root.findByName('Pipe 3');
this.heights = [];
this.heights.push((Math.random() - 0.5) * 0.8 + 0.1);
this.heights.push((Math.random() - 0.5) * 0.8 + 0.1);
this.heights.push((Math.random() - 0.5) * 0.8 + 0.1);
this.setPipeHeights();
app.on('pipes:cycle', function () {
this.heights.shift();
this.heights.push((Math.random() - 0.5) * 0.75);
this.setPipeHeights();
}, this);
}
setPipeHeights () {
// this.pipe1 = this.pipe1 ?? app.root.findByName('Pipe 1');
// this.pipe2 = this.pipe2 ?? app.root.findByName('Pipe 2');
// this.pipe3 = this.pipe3 ?? app.root.findByName('Pipe 3');
// if(!this.pipe1 || !this.pipe2 || !this.pipe3) {
// return;
// }
var pos;
pos = this.pipe1.getLocalPosition();
this.pipe1.setLocalPosition(pos.x, this.heights[0], pos.z);
pos = this.pipe2.getLocalPosition();
this.pipe2.setLocalPosition(pos.x, this.heights[1], pos.z);
pos = this.pipe3.getLocalPosition();
this.pipe3.setLocalPosition(pos.x, this.heights[2], pos.z);
}
}