From 65c8f7cc45d9839671d6c71c7007af2c4149e366 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 4 Mar 2016 17:55:45 -0800 Subject: [PATCH] flowers growing --- .../plant/growingPlantEntityScript.js | 23 +++++++++++++------ .../homeContent/plant/waterCanEntityScript.js | 9 ++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 0849a3931b..4664a710f8 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -20,11 +20,14 @@ _this.flowers = []; // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} _this.STARTING_FLOWER_DIMENSIONS = { - x: 0.1, - y: 0.01, - z: 0.1 + x: 0.001, + y: 0.001, + z: 0.001 } + _this.debounceRange = {min: 500, max: 1000}; + _this.canCreateFlower = true; + }; GrowingPlant.prototype = { @@ -34,9 +37,14 @@ // we're being watered- every now and then spawn a new flower to add to our growing list // If we don't have any flowers yet, immediately grow one var data = JSON.parse(data[0]); - if (_this.flowers.length < 1000) { - _this.createFlower(data.position, data.surfaceNormal); + if(_this.canCreateFlower) { + _this.createFlower(data.position, data.surfaceNormal); + _this.canCreateFlower = false; + Script.setTimeout(function() { + _this.canCreateFlower = true; + }, randFloat(_this.debounceRange.min, this.debounceRange.max)); + } _this.flowers.forEach(function(flower) { @@ -44,6 +52,7 @@ }); + }, createFlower: function(position, surfaceNormal) { @@ -64,7 +73,7 @@ startingPosition: position, rotation: flowerRotation, maxYDimension: randFloat(0.2, 1.5), - growthRate: randFloat(0.0001, 0.001) + growthRate: {x: 0.0002, y: 0.001, z: 0.0002} }; print(_this.STARTING_FLOWER_DIMENSIONS.y) flower.grow = function() { @@ -72,7 +81,7 @@ if (flower.dimensions.y > flower.maxYDimension) { return; } - flower.dimensions.y += flower.growthRate; + flower.dimensions = Vec3.sum(flower.dimensions, flower.growthRate); flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y / 2)); //As we grow we must also move ourselves in direction we grow! Entities.editEntity(flower.id, { diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 63841d08d4..0734b98885 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -64,7 +64,7 @@ castRay: function() { var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]); var direction = Quat.getFront(spoutProps.rotation) - var end = Vec3.sum(spoutProps.position, Vec3.multiply(10, direction)); + var end = Vec3.sum(spoutProps.position, Vec3.multiply(5, direction)); Overlays.editOverlay(_this.rayCastLine, { start: spoutProps.position, end: end @@ -131,9 +131,10 @@ z: 0.01 }, emitOrientation: Quat.fromPitchYawRollDegrees(0, 180, 0), - particleRadius: 0.04, - radiusSpread: 0.01, - radiusStart: 0.03, + particleRadius: 0.01, + radiusSpread: 0.001, + radiusStart: 0.01, + radiusFinish: 0.01, alpha: 0.9, alphaSpread: .1, alphaStart: 0.7,