overte-HifiExperiments/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js
James B. Pollack 46fbf38b5d ac movers
2016-02-24 12:36:18 -08:00

106 lines
No EOL
2.6 KiB
JavaScript

var basePosition = {
x: 3000,
y: 13500,
z: 3000
};
var initialized = false;
EntityViewer.setPosition(basePosition);
EntityViewer.setKeyholeRadius(60000);
var octreeQueryInterval = Script.setInterval(function() {
EntityViewer.queryOctree();
}, 200);
var THROTTLE = true;
var THROTTLE_RATE = 5000;
var sinceLastUpdate = 0;
print('vesicle script')
function findVesicles() {
var results = Entities.findEntities(basePosition, 60000);
if (results.length === 0) {
print('no entities found')
return;
}
results.forEach(function(v) {
var name = Entities.getEntityProperties(v, 'name').name;
print('name is:: ' + name)
if (name === 'vesicle') {
print('found a vesicle!!' + v)
Script.setTimeout(function() {
moveVesicle(v);
}, Math.random() * THROTTLE_RATE)
}
});
}
var minVelocity = 1;
var maxVelocity = 5;
var minAngularVelocity = 0.01;
var maxAngularVelocity = 0.03;
function moveVesicle(entityId) {
print('moving a vesicle! ' + entityId)
var magnitudeV = maxVelocity;
var directionV = {
x: Math.random() - 0.5,
y: Math.random() - 0.5,
z: Math.random() - 0.5
};
print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x);
var magnitudeAV = maxAngularVelocity;
var directionAV = {
x: Math.random() - 0.5,
y: Math.random() - 0.5,
z: Math.random() - 0.5
};
print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x);
Entities.editEntity(entityId, {
velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)),
angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV))
});
}
function update(deltaTime) {
// print('deltaTime',deltaTime)
if (!initialized) {
print("checking for servers...");
if (Entities.serversExist() && Entities.canRez()) {
print("servers exist -- makeAll...");
Entities.setPacketsPerSecond(6000);
print("PPS:" + Entities.getPacketsPerSecond());
initialized = true;
}
return;
}
if (THROTTLE === true) {
sinceLastUpdate = sinceLastUpdate + deltaTime * 1000;
if (sinceLastUpdate > THROTTLE_RATE) {
print('SHOULD FIND VESICLES!!!')
sinceLastUpdate = 0;
findVesicles();
} else {
// print('returning in update ' + sinceLastUpdate)
return;
}
}
}
function unload() {
Script.update.disconnect(update);
}
Script.update.connect(update);
Script.scriptEnding.connect(unload);