overte-thingvellir/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly_orig.js
James B. Pollack 0e036d3e2c cellscience
2016-01-29 16:58:49 -08:00

49 lines
No EOL
1.4 KiB
JavaScript

(function(){
var self = this;
this.preload = function(entityId) {
this.entityId = entityId;
this.updateInterval = 30;
this.frame = 0;
this.minVelocity = 0.15;
this.maxVelocity = 0.35;
this.minAngularVelocity = 0.3;
this.maxAngularVelocity = 0.7;
}
this.update = function(deltaTime) {
self.frame++;
if (self.frame > self.updateInterval) {
self.updateInterval = 20 * Math.random() + 0;
self.frame = 0;
var magnitudeV = (self.maxVelocity - self.minVelocity) * Math.random() + self.minVelocity;
var magnitudeAV = (self.maxAngularVelocity - self.minAngularVelocity) * Math.random() + self.minAngularVelocity;
var directionV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
var directionAV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
Entities.editEntity(self.entityId, {
velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)),
angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV))
});
}
}
this.unload = function() {
Script.update.disconnect(this.update);
}
Script.update.connect(this.update);
})