-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplash_plane.js
More file actions
54 lines (44 loc) · 1.78 KB
/
splash_plane.js
File metadata and controls
54 lines (44 loc) · 1.78 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
pc.script.attribute('rollSpeed', 'number', 10);
pc.script.attribute('rollAcceleration', 'number', 7);
pc.script.attribute('maxRoll', 'number', 2);
pc.script.attribute('panAmount', 'number', 0.1);
pc.script.create('splash_plane', function (context) {
var euler = new pc.Vec3();
var Splash_plane = function (entity) {
this.entity = entity;
};
Splash_plane.prototype = {
initialize: function () {
this.roll = 0;
this.rollVel = 0;
this.rollAcc = this.rollAcceleration;
this.pan = this.entity.getLocalPosition().x;
this.gameCamera = context.root.findByName('Camera');
},
onEnable: function () {
this.gameCamera.enabled = false;
},
onDisable: function () {
this.gameCamera.enabled = true;
},
update: function (dt) {
this.rollVel = pc.math.clamp(this.rollVel + this.rollAcc * dt, -this.rollSpeed, this.rollSpeed);
this.roll += this.rollVel * dt;
if (this.roll > this.maxRoll && this.rollAcc > 0) {
this.rollAcc = -this.rollAcceleration;
}
else if (this.roll < -this.maxRoll && this.rollAcc < 0) {
this.rollAcc = this.rollAcceleration;
}
var localRotation = this.entity.getLocalRotation();
localRotation.getEulerAngles(euler);
euler.z = this.roll;
localRotation.setFromEulerAngles(euler.x, euler.y, euler.z);
this.entity.setLocalRotation(localRotation);
var localPos = this.entity.getLocalPosition();
localPos.x = this.pan - this.roll * this.panAmount;
this.entity.setLocalPosition(localPos);
}
};
return Splash_plane;
});