From ef437b7f99b695304d0206af88c63ca9ccd04204 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 4 Mar 2016 16:48:55 -0800 Subject: [PATCH] flowers staying in place --- .../plant/growingPlantEntityScript.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 89b84f3ffb..63bd60023b 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -19,7 +19,7 @@ _this = this; _this.flowers = []; // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} - _this.STARTING_FLOWER_DIMENSIONS = {x: 0.01, y: 0.01, z: 0.02} + _this.STARTING_FLOWER_DIMENSIONS = {x: 0.2, y: 0.01, z: 0.2} }; @@ -30,7 +30,7 @@ // 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 < 10) { + if (_this.flowers.length < 1000) { _this.createFlower(data.position, data.surfaceNormal); } @@ -43,7 +43,7 @@ }, createFlower: function(position, surfaceNormal) { - var flowerRotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, surfaceNormal); + var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); print("flower rotation " + flowerRotation.x) var flowerEntityID = Entities.addEntity({ type: "Sphere", @@ -51,14 +51,16 @@ position: position, rotation: flowerRotation, dimensions: _this.STARTING_FLOWER_DIMENSIONS, - // userData: JSON.stringify(_this.flowerUserData) + userData: JSON.stringify(_this.flowerUserData) }); - var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS}; + var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS, startingPosition: position, rotation: flowerRotation}; flower.grow = function() { // grow flower a bit - flower.dimensions.z += 0.0001; - Entities.editEntity(flower.id, {dimensions: flower.dimensions}); + flower.dimensions.y += 0.001; + 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, {dimensions: flower.dimensions, position: flower.position}); } _this.flowers.push(flower); },