content/hifi-public/cellscience/Scripts/moveRandomly_orig.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

49 lines
No EOL
1.5 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);
})