step back message (fixes #93)

This commit is contained in:
Diego F. Goberna
2018-10-16 02:55:47 +02:00
parent 3bee7197ca
commit b6fbd6003f
4 changed files with 38 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
AFRAME.registerComponent('stepback', {
init: function () {
this.message = document.getElementById('stepback');
this.camera = document.getElementById('camera');
this.lastTime = 0;
this.limit = - (this.el.getAttribute('geometry').height / 2 - 0.6);
this.throttling = 300;
},
tick: function (time, delta) {
if (time - this.lastTime < this.throttling) { return; }
var camPos = this.camera.object3D.position;
var msgPos = this.message.object3D.position;
if (camPos.z < this.limit) {
this.throttling = 20;
this.message.object3D.visible = true;
this.message.getObject3D('mesh').material.opacity = 1 - Math.abs(camPos.z - msgPos.z);
msgPos.x = camPos.x;
msgPos.y = camPos.y;
}
else {
this.message.object3D.visible = false;
this.throttling = 300;
}
this.lastTime = time;
}
});