From 1873558df15ec8d8bbbdcac7a275738469c1af10 Mon Sep 17 00:00:00 2001 From: Rob Kayson Date: Sat, 6 May 2017 18:41:57 -0700 Subject: [PATCH 1/4] added floating lantern box that spawns floating lanterns --- scripts/tutorials/createFloatingLanternBox.js | 42 +++++++ .../entity_scripts/floatingLantern.js | 106 ++++++++++++++++++ .../entity_scripts/floatingLanternBox.js | 101 +++++++++++++++++ 3 files changed, 249 insertions(+) create mode 100644 scripts/tutorials/createFloatingLanternBox.js create mode 100644 scripts/tutorials/entity_scripts/floatingLantern.js create mode 100644 scripts/tutorials/entity_scripts/floatingLanternBox.js diff --git a/scripts/tutorials/createFloatingLanternBox.js b/scripts/tutorials/createFloatingLanternBox.js new file mode 100644 index 0000000000..611e995fcb --- /dev/null +++ b/scripts/tutorials/createFloatingLanternBox.js @@ -0,0 +1,42 @@ +"use strict"; +/* jslint vars: true, plusplus: true, forin: true*/ +/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */ +/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ +// +// createFloatinLanternBox.js +// +// Created by MrRoboman on 17/05/04 +// Copyright 2017 High Fidelity, Inc. +// +// Creates a crate that spawn floating lanterns +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +var COMPOUND_SHAPE_URL = "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/maracas/woodenCrate_phys.obj"; +var MODEL_URL = "http://hifi-content.s3.amazonaws.com/Examples%20Content/production/maracas/woodenCrate_VR.fbx"; +var SCRIPT_URL = Script.resolvePath("./entity_scripts/floatingLanternBox.js?v=" + Date.now()); +var START_POSITION = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2)); +START_POSITION.y -= .6; +var LIFETIME = 3600; + +var lanternBox = { + type: "Model", + name: "Floating Lantern Box", + description: "Spawns Lanterns that float away when grabbed and released!", + script: SCRIPT_URL, + modelURL: MODEL_URL, + shapeType: "Compound", + compoundShapeURL: COMPOUND_SHAPE_URL, + position: START_POSITION, + lifetime: LIFETIME, + dimensions: { + x: 0.8696, + y: 0.58531, + z: 0.9264 + }, + owningAvatarID: MyAvatar.sessionUUID +}; + +Entities.addEntity(lanternBox); +Script.stop(); diff --git a/scripts/tutorials/entity_scripts/floatingLantern.js b/scripts/tutorials/entity_scripts/floatingLantern.js new file mode 100644 index 0000000000..8fa2828c90 --- /dev/null +++ b/scripts/tutorials/entity_scripts/floatingLantern.js @@ -0,0 +1,106 @@ +"use strict"; +/* jslint vars: true, plusplus: true, forin: true*/ +/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */ +/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ +// +// floatinLantern.js +// +// Created by MrRoboman on 17/05/04 +// Copyright 2017 High Fidelity, Inc. +// +// Makes floating lanterns rise upon being released and corrects their rotation as the fly. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +(function() { + var _this; + + var SLOW_SPIN_THRESHOLD = 0.1; + var ROTATION_COMPLETE_THRESHOLD = 0.01; + var ROTATION_SPEED = 0.2; + var HOME_ROTATION = {x: 0, y: 0, z: 0, w: 0}; + + + floatingLantern = function() { + _this = this; + this.updateConnected = false; + }; + + floatingLantern.prototype = { + + preload: function(entityID) { + this.entityID = entityID; + }, + + unload: function(entityID) { + this.disconnectUpdate(); + }, + + startNearGrab: function() { + this.disconnectUpdate(); + }, + + startDistantGrab: function() { + this.disconnectUpdate(); + }, + + releaseGrab: function() { + Entities.editEntity(this.entityID, { + gravity: { + x: 0, + y: 0.5, + z: 0 + } + }); + }, + + update: function(dt) { + var lanternProps = Entities.getEntityProperties(_this.entityID); + + if(lanternProps && lanternProps.rotation && lanternProps.owningAvatarID === MyAvatar.sessionUUID) { + + var spinningSlowly = ( + Math.abs(lanternProps.angularVelocity.x) < SLOW_SPIN_THRESHOLD && + Math.abs(lanternProps.angularVelocity.y) < SLOW_SPIN_THRESHOLD && + Math.abs(lanternProps.angularVelocity.z) < SLOW_SPIN_THRESHOLD + ); + + var rotationComplete = ( + Math.abs(lanternProps.rotation.x - HOME_ROTATION.x) < ROTATION_COMPLETE_THRESHOLD && + Math.abs(lanternProps.rotation.y - HOME_ROTATION.y) < ROTATION_COMPLETE_THRESHOLD && + Math.abs(lanternProps.rotation.z - HOME_ROTATION.z) < ROTATION_COMPLETE_THRESHOLD + ); + + if(spinningSlowly && !rotationComplete) { + var newRotation = Quat.slerp(lanternProps.rotation, HOME_ROTATION, ROTATION_SPEED * dt); + + Entities.editEntity(_this.entityID, { + rotation: newRotation, + angularVelocity: { + x: 0, + y: 0, + z: 0 + } + }); + } + } + }, + + connectUpdate: function() { + if(!this.updateConnected) { + this.updateConnected = true; + Script.update.connect(this.update); + } + }, + + disconnectUpdate: function() { + if(this.updateConnected) { + this.updateConnected = false; + Script.update.disconnect(this.update); + } + } + }; + + return new floatingLantern(); +}); diff --git a/scripts/tutorials/entity_scripts/floatingLanternBox.js b/scripts/tutorials/entity_scripts/floatingLanternBox.js new file mode 100644 index 0000000000..2c483f6129 --- /dev/null +++ b/scripts/tutorials/entity_scripts/floatingLanternBox.js @@ -0,0 +1,101 @@ +"use strict"; +/* jslint vars: true, plusplus: true, forin: true*/ +/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */ +/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ +// +// floatingLanternBox.js +// +// Created by MrRoboman on 17/05/04 +// Copyright 2017 High Fidelity, Inc. +// +// Spawns new floating lanterns every couple seconds if the old ones have been removed. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +(function() { + + var _this; + var LANTERN_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Welcome%20Area/Models/chinaLantern_capsule.fbx"; + var LANTERN_SCRIPT_URL = Script.resolvePath("floatingLantern.js?v=" + Date.now()); + var LIFETIME = 120; + var RESPAWN_INTERVAL = 1000; + var MAX_LANTERNS = 4; + + var LANTERN = { + type: "Model", + name: "Floating Lantern", + description: "Spawns Lanterns that float away when grabbed and released!", + modelURL: LANTERN_MODEL_URL, + script: LANTERN_SCRIPT_URL, + dimensions: { + x: 0.2049, + y: 0.4, + z: 0.2049 + }, + gravity: { + x: 0, + y: -1, + z: 0 + }, + velocity: { + x: 0, y: .01, z: 0 + }, + linearDampening: 0, + shapeType: 'Box', + lifetime: LIFETIME, + dynamic: true + }; + + lanternBox = function() { + _this = this; + }; + + lanternBox.prototype = { + + preload: function(entityID) { + this.entityID = entityID; + var props = Entities.getEntityProperties(this.entityID); + + if(props.owningAvatarID === MyAvatar.sessionUUID){ + this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL); + } + }, + + unload: function(entityID) { + if(this.respawnTimer) + Script.clearInterval(this.respawnTimer); + }, + + spawnAllLanterns: function() { + var props = Entities.getEntityProperties(this.entityID); + var lanternCount = 0; + var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75); + + for(var i = 0; i < nearbyEntities.length; i++) { + var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name; + if(name === "Floating Lantern") { + lanternCount++; + } + } + + while(lanternCount++ < MAX_LANTERNS) { + this.spawnLantern(); + } + }, + + spawnLantern: function() { + var boxProps = Entities.getEntityProperties(this.entityID); + + LANTERN.position = boxProps.position; + LANTERN.position.x += Math.random() * .2 - .1; + LANTERN.position.y += Math.random() * .2 + .1; + LANTERN.position.z += Math.random() * .2 - .1; + LANTERN.owningAvatarID = boxProps.owningAvatarID; + + return Entities.addEntity(LANTERN); + } + }; + + return new lanternBox(); +}); From a12e8e34dbd5833b8013cfbcfbeac267a32538e1 Mon Sep 17 00:00:00 2001 From: Rob Kayson Date: Fri, 12 May 2017 15:06:22 -0700 Subject: [PATCH 2/4] coding standard --- scripts/tutorials/createFloatingLanternBox.js | 7 +- .../entity_scripts/floatingLantern.js | 168 +++++++++--------- .../entity_scripts/floatingLanternBox.js | 20 ++- 3 files changed, 99 insertions(+), 96 deletions(-) diff --git a/scripts/tutorials/createFloatingLanternBox.js b/scripts/tutorials/createFloatingLanternBox.js index 611e995fcb..a925cfff22 100644 --- a/scripts/tutorials/createFloatingLanternBox.js +++ b/scripts/tutorials/createFloatingLanternBox.js @@ -19,6 +19,7 @@ var SCRIPT_URL = Script.resolvePath("./entity_scripts/floatingLanternBox.js?v=" var START_POSITION = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), 2)); START_POSITION.y -= .6; var LIFETIME = 3600; +var SCALE_FACTOR = 1; var lanternBox = { type: "Model", @@ -31,9 +32,9 @@ var lanternBox = { position: START_POSITION, lifetime: LIFETIME, dimensions: { - x: 0.8696, - y: 0.58531, - z: 0.9264 + x: 0.8696 * SCALE_FACTOR, + y: 0.58531 * SCALE_FACTOR, + z: 0.9264 * SCALE_FACTOR }, owningAvatarID: MyAvatar.sessionUUID }; diff --git a/scripts/tutorials/entity_scripts/floatingLantern.js b/scripts/tutorials/entity_scripts/floatingLantern.js index 8fa2828c90..aa25dc0003 100644 --- a/scripts/tutorials/entity_scripts/floatingLantern.js +++ b/scripts/tutorials/entity_scripts/floatingLantern.js @@ -14,93 +14,93 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html (function() { - var _this; + var _this; - var SLOW_SPIN_THRESHOLD = 0.1; - var ROTATION_COMPLETE_THRESHOLD = 0.01; - var ROTATION_SPEED = 0.2; - var HOME_ROTATION = {x: 0, y: 0, z: 0, w: 0}; + var SLOW_SPIN_THRESHOLD = 0.1; + var ROTATION_COMPLETE_THRESHOLD = 0.01; + var ROTATION_SPEED = 0.2; + var HOME_ROTATION = {x: 0, y: 0, z: 0, w: 0}; - floatingLantern = function() { - _this = this; - this.updateConnected = false; - }; - - floatingLantern.prototype = { - - preload: function(entityID) { - this.entityID = entityID; - }, - - unload: function(entityID) { - this.disconnectUpdate(); - }, - - startNearGrab: function() { - this.disconnectUpdate(); - }, - - startDistantGrab: function() { - this.disconnectUpdate(); - }, - - releaseGrab: function() { - Entities.editEntity(this.entityID, { - gravity: { - x: 0, - y: 0.5, - z: 0 - } - }); - }, - - update: function(dt) { - var lanternProps = Entities.getEntityProperties(_this.entityID); - - if(lanternProps && lanternProps.rotation && lanternProps.owningAvatarID === MyAvatar.sessionUUID) { - - var spinningSlowly = ( - Math.abs(lanternProps.angularVelocity.x) < SLOW_SPIN_THRESHOLD && - Math.abs(lanternProps.angularVelocity.y) < SLOW_SPIN_THRESHOLD && - Math.abs(lanternProps.angularVelocity.z) < SLOW_SPIN_THRESHOLD - ); - - var rotationComplete = ( - Math.abs(lanternProps.rotation.x - HOME_ROTATION.x) < ROTATION_COMPLETE_THRESHOLD && - Math.abs(lanternProps.rotation.y - HOME_ROTATION.y) < ROTATION_COMPLETE_THRESHOLD && - Math.abs(lanternProps.rotation.z - HOME_ROTATION.z) < ROTATION_COMPLETE_THRESHOLD - ); - - if(spinningSlowly && !rotationComplete) { - var newRotation = Quat.slerp(lanternProps.rotation, HOME_ROTATION, ROTATION_SPEED * dt); - - Entities.editEntity(_this.entityID, { - rotation: newRotation, - angularVelocity: { - x: 0, - y: 0, - z: 0 - } - }); - } - } - }, - - connectUpdate: function() { - if(!this.updateConnected) { - this.updateConnected = true; - Script.update.connect(this.update); - } - }, - - disconnectUpdate: function() { - if(this.updateConnected) { + floatingLantern = function() { + _this = this; this.updateConnected = false; - Script.update.disconnect(this.update); - } - } - }; + }; - return new floatingLantern(); + floatingLantern.prototype = { + + preload: function(entityID) { + this.entityID = entityID; + }, + + unload: function(entityID) { + this.disconnectUpdate(); + }, + + startNearGrab: function() { + this.disconnectUpdate(); + }, + + startDistantGrab: function() { + this.disconnectUpdate(); + }, + + releaseGrab: function() { + Entities.editEntity(this.entityID, { + gravity: { + x: 0, + y: 0.5, + z: 0 + } + }); + }, + + update: function(dt) { + var lanternProps = Entities.getEntityProperties(_this.entityID); + + if (lanternProps && lanternProps.rotation && lanternProps.owningAvatarID === MyAvatar.sessionUUID) { + + var spinningSlowly = ( + Math.abs(lanternProps.angularVelocity.x) < SLOW_SPIN_THRESHOLD && + Math.abs(lanternProps.angularVelocity.y) < SLOW_SPIN_THRESHOLD && + Math.abs(lanternProps.angularVelocity.z) < SLOW_SPIN_THRESHOLD + ); + + var rotationComplete = ( + Math.abs(lanternProps.rotation.x - HOME_ROTATION.x) < ROTATION_COMPLETE_THRESHOLD && + Math.abs(lanternProps.rotation.y - HOME_ROTATION.y) < ROTATION_COMPLETE_THRESHOLD && + Math.abs(lanternProps.rotation.z - HOME_ROTATION.z) < ROTATION_COMPLETE_THRESHOLD + ); + + if (spinningSlowly && !rotationComplete) { + var newRotation = Quat.slerp(lanternProps.rotation, HOME_ROTATION, ROTATION_SPEED * dt); + + Entities.editEntity(_this.entityID, { + rotation: newRotation, + angularVelocity: { + x: 0, + y: 0, + z: 0 + } + }); + } + } + }, + + connectUpdate: function() { + if (!this.updateConnected) { + this.updateConnected = true; + Script.update.connect(this.update); + } + }, + + disconnectUpdate: function() { + if (this.updateConnected) { + this.updateConnected = false; + Script.update.disconnect(this.update); + } + } + }; + + return new floatingLantern(); }); diff --git a/scripts/tutorials/entity_scripts/floatingLanternBox.js b/scripts/tutorials/entity_scripts/floatingLanternBox.js index 2c483f6129..ba44fbaa9d 100644 --- a/scripts/tutorials/entity_scripts/floatingLanternBox.js +++ b/scripts/tutorials/entity_scripts/floatingLanternBox.js @@ -21,6 +21,7 @@ var LIFETIME = 120; var RESPAWN_INTERVAL = 1000; var MAX_LANTERNS = 4; + var SCALE_FACTOR = 1; var LANTERN = { type: "Model", @@ -29,9 +30,9 @@ modelURL: LANTERN_MODEL_URL, script: LANTERN_SCRIPT_URL, dimensions: { - x: 0.2049, - y: 0.4, - z: 0.2049 + x: 0.2049 * SCALE_FACTOR, + y: 0.4 * SCALE_FACTOR, + z: 0.2049 * SCALE_FACTOR }, gravity: { x: 0, @@ -57,14 +58,15 @@ this.entityID = entityID; var props = Entities.getEntityProperties(this.entityID); - if(props.owningAvatarID === MyAvatar.sessionUUID){ + if (props.owningAvatarID === MyAvatar.sessionUUID) { this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL); } }, unload: function(entityID) { - if(this.respawnTimer) - Script.clearInterval(this.respawnTimer); + if (this.respawnTimer) { + Script.clearInterval(this.respawnTimer); + } }, spawnAllLanterns: function() { @@ -72,14 +74,14 @@ var lanternCount = 0; var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75); - for(var i = 0; i < nearbyEntities.length; i++) { + for (var i = 0; i < nearbyEntities.length; i++) { var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name; - if(name === "Floating Lantern") { + if (name === "Floating Lantern") { lanternCount++; } } - while(lanternCount++ < MAX_LANTERNS) { + while (lanternCount++ < MAX_LANTERNS) { this.spawnLantern(); } }, From f3d8d1641f62b36365671dcf8f085bbfc97aa40e Mon Sep 17 00:00:00 2001 From: Rob Kayson Date: Fri, 12 May 2017 15:10:40 -0700 Subject: [PATCH 3/4] fix indent createFloatingLanternBox.js --- scripts/tutorials/createFloatingLanternBox.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/tutorials/createFloatingLanternBox.js b/scripts/tutorials/createFloatingLanternBox.js index a925cfff22..c84214e295 100644 --- a/scripts/tutorials/createFloatingLanternBox.js +++ b/scripts/tutorials/createFloatingLanternBox.js @@ -22,21 +22,21 @@ var LIFETIME = 3600; var SCALE_FACTOR = 1; var lanternBox = { - type: "Model", - name: "Floating Lantern Box", - description: "Spawns Lanterns that float away when grabbed and released!", - script: SCRIPT_URL, - modelURL: MODEL_URL, - shapeType: "Compound", - compoundShapeURL: COMPOUND_SHAPE_URL, - position: START_POSITION, - lifetime: LIFETIME, - dimensions: { - x: 0.8696 * SCALE_FACTOR, - y: 0.58531 * SCALE_FACTOR, - z: 0.9264 * SCALE_FACTOR - }, - owningAvatarID: MyAvatar.sessionUUID + type: "Model", + name: "Floating Lantern Box", + description: "Spawns Lanterns that float away when grabbed and released!", + script: SCRIPT_URL, + modelURL: MODEL_URL, + shapeType: "Compound", + compoundShapeURL: COMPOUND_SHAPE_URL, + position: START_POSITION, + lifetime: LIFETIME, + dimensions: { + x: 0.8696 * SCALE_FACTOR, + y: 0.58531 * SCALE_FACTOR, + z: 0.9264 * SCALE_FACTOR + }, + owningAvatarID: MyAvatar.sessionUUID }; Entities.addEntity(lanternBox); From 9fc0ad0d28dc79aa258e82f7c9af0229163570a6 Mon Sep 17 00:00:00 2001 From: Rob Kayson Date: Fri, 12 May 2017 15:12:43 -0700 Subject: [PATCH 4/4] fix indent floatingLanternBox --- .../entity_scripts/floatingLanternBox.js | 150 +++++++++--------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/scripts/tutorials/entity_scripts/floatingLanternBox.js b/scripts/tutorials/entity_scripts/floatingLanternBox.js index ba44fbaa9d..b5fb0c27d9 100644 --- a/scripts/tutorials/entity_scripts/floatingLanternBox.js +++ b/scripts/tutorials/entity_scripts/floatingLanternBox.js @@ -15,89 +15,89 @@ (function() { - var _this; - var LANTERN_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Welcome%20Area/Models/chinaLantern_capsule.fbx"; - var LANTERN_SCRIPT_URL = Script.resolvePath("floatingLantern.js?v=" + Date.now()); - var LIFETIME = 120; - var RESPAWN_INTERVAL = 1000; - var MAX_LANTERNS = 4; - var SCALE_FACTOR = 1; + var _this; + var LANTERN_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Welcome%20Area/Models/chinaLantern_capsule.fbx"; + var LANTERN_SCRIPT_URL = Script.resolvePath("floatingLantern.js?v=" + Date.now()); + var LIFETIME = 120; + var RESPAWN_INTERVAL = 1000; + var MAX_LANTERNS = 4; + var SCALE_FACTOR = 1; - var LANTERN = { - type: "Model", - name: "Floating Lantern", - description: "Spawns Lanterns that float away when grabbed and released!", - modelURL: LANTERN_MODEL_URL, - script: LANTERN_SCRIPT_URL, - dimensions: { - x: 0.2049 * SCALE_FACTOR, - y: 0.4 * SCALE_FACTOR, - z: 0.2049 * SCALE_FACTOR - }, - gravity: { - x: 0, - y: -1, - z: 0 - }, - velocity: { - x: 0, y: .01, z: 0 - }, - linearDampening: 0, - shapeType: 'Box', - lifetime: LIFETIME, - dynamic: true - }; + var LANTERN = { + type: "Model", + name: "Floating Lantern", + description: "Spawns Lanterns that float away when grabbed and released!", + modelURL: LANTERN_MODEL_URL, + script: LANTERN_SCRIPT_URL, + dimensions: { + x: 0.2049 * SCALE_FACTOR, + y: 0.4 * SCALE_FACTOR, + z: 0.2049 * SCALE_FACTOR + }, + gravity: { + x: 0, + y: -1, + z: 0 + }, + velocity: { + x: 0, y: .01, z: 0 + }, + linearDampening: 0, + shapeType: 'Box', + lifetime: LIFETIME, + dynamic: true + }; - lanternBox = function() { - _this = this; - }; + lanternBox = function() { + _this = this; + }; - lanternBox.prototype = { + lanternBox.prototype = { - preload: function(entityID) { - this.entityID = entityID; - var props = Entities.getEntityProperties(this.entityID); + preload: function(entityID) { + this.entityID = entityID; + var props = Entities.getEntityProperties(this.entityID); - if (props.owningAvatarID === MyAvatar.sessionUUID) { - this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL); - } - }, + if (props.owningAvatarID === MyAvatar.sessionUUID) { + this.respawnTimer = Script.setInterval(this.spawnAllLanterns.bind(this), RESPAWN_INTERVAL); + } + }, - unload: function(entityID) { - if (this.respawnTimer) { - Script.clearInterval(this.respawnTimer); - } - }, + unload: function(entityID) { + if (this.respawnTimer) { + Script.clearInterval(this.respawnTimer); + } + }, - spawnAllLanterns: function() { - var props = Entities.getEntityProperties(this.entityID); - var lanternCount = 0; - var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75); + spawnAllLanterns: function() { + var props = Entities.getEntityProperties(this.entityID); + var lanternCount = 0; + var nearbyEntities = Entities.findEntities(props.position, props.dimensions.x * 0.75); - for (var i = 0; i < nearbyEntities.length; i++) { - var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name; - if (name === "Floating Lantern") { - lanternCount++; + for (var i = 0; i < nearbyEntities.length; i++) { + var name = Entities.getEntityProperties(nearbyEntities[i], ["name"]).name; + if (name === "Floating Lantern") { + lanternCount++; + } + } + + while (lanternCount++ < MAX_LANTERNS) { + this.spawnLantern(); + } + }, + + spawnLantern: function() { + var boxProps = Entities.getEntityProperties(this.entityID); + + LANTERN.position = boxProps.position; + LANTERN.position.x += Math.random() * .2 - .1; + LANTERN.position.y += Math.random() * .2 + .1; + LANTERN.position.z += Math.random() * .2 - .1; + LANTERN.owningAvatarID = boxProps.owningAvatarID; + + return Entities.addEntity(LANTERN); } - } + }; - while (lanternCount++ < MAX_LANTERNS) { - this.spawnLantern(); - } - }, - - spawnLantern: function() { - var boxProps = Entities.getEntityProperties(this.entityID); - - LANTERN.position = boxProps.position; - LANTERN.position.x += Math.random() * .2 - .1; - LANTERN.position.y += Math.random() * .2 + .1; - LANTERN.position.z += Math.random() * .2 - .1; - LANTERN.owningAvatarID = boxProps.owningAvatarID; - - return Entities.addEntity(LANTERN); - } - }; - - return new lanternBox(); + return new lanternBox(); });