r3-custom-code/94xi7aitax.js

70 lines
1.5 KiB
JavaScript

if (!this.entityLoaded) {
return;
}
if (!this.initialized) {
/**
* Meshes
*/
this.sections = this.entityLoaded.sections;
this.cloud = this.entityLoaded.cloud;
this.camera = this.entityLoaded.camera;
this.snail = this.entityLoaded.snail;
this.time = 0;
this.speed = 50;
this.spawnCloud = function() {
this.cloud.position.x = -155;
this.cloud.position.z = (Math.random() * 10) - 5;
this.cloud.updateInstance('position');
}
this.initialized = true;
}
var diff = data.delta * this.speed;
this.cloud.position.x += diff;
this.cloud.updateInstance('position');
this.sections.map(
function(section) {
section.left.position.x += diff;
section.road.position.x += diff;
section.right.position.x += diff;
if (section.left.position.x > 50) {
section.left.position.x -= 200;
section.road.position.x -= 200;
section.right.position.x -= 200;
}
section.left.updateInstance('position');
section.road.updateInstance('position');
section.right.updateInstance('position');
}
);
if (this.camera.position.z < this.snail.position.z) {
this.camera.position.z += data.delta;
} else {
this.camera.position.z -= data.delta;
}
this.camera.updateInstance('position');
this.camera.lookAt.x = this.snail.position.x;
this.camera.lookAt.y = this.snail.position.y;
this.camera.lookAt.z = this.snail.position.z;
this.camera.updateInstance('lookAt');
this.time += data.delta;
if (this.time > 5) {
this.spawnCloud();
this.time = 0;
}
//@ sourceURL=beforeRender.js