From 15ea9219d6c9110a26ceb8f615eef11c5e61c438 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Sep 2015 10:41:44 -0700 Subject: [PATCH] collision timeouts --- examples/toys/bubblewand/bubble.js | 16 +++++++++++++--- examples/toys/bubblewand/wand.js | 25 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/examples/toys/bubblewand/bubble.js b/examples/toys/bubblewand/bubble.js index f69116ef92..ebb5a36d2d 100644 --- a/examples/toys/bubblewand/bubble.js +++ b/examples/toys/bubblewand/bubble.js @@ -16,6 +16,8 @@ var BUBBLE_PARTICLE_TEXTURE = "http://hifi-public.s3.amazonaws.com/james/bubblewand/textures/bubble_particle.png" + var BUBBLE_USER_DATA_KEY = "BubbleKey"; + BUBBLE_PARTICLE_COLOR = { red: 0, green: 40, @@ -44,8 +46,16 @@ this.unload = function(entityID) { Script.update.disconnect(this.update); - //TODO: Unload doesn't seem like the right place to do this. We really want to know that our lifetime is over. - // _this.createBurstParticles(); + var defaultGrabData = { + avatarId: null + }; + + var bubbleCreator = getEntityCustomData(BUBBLE_USER_DATA_KEY, entityID, defaultGrabData); + + if (bubbleCreator === MyAvatar.sessionUUID) { + this.createBurstParticles(); + } + }; @@ -90,7 +100,7 @@ y: -0.1, z: 0 }, - particleRadius:0.1, + particleRadius: 0.1, alphaStart: 0.5, alpha: 0.5, alphaFinish: 0, diff --git a/examples/toys/bubblewand/wand.js b/examples/toys/bubblewand/wand.js index 9da4901d56..0e960f1f64 100644 --- a/examples/toys/bubblewand/wand.js +++ b/examples/toys/bubblewand/wand.js @@ -10,6 +10,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + (function() { Script.include("../../utilities.js"); @@ -18,6 +19,7 @@ var BUBBLE_MODEL = "http://hifi-public.s3.amazonaws.com/james/bubblewand/models/bubble/bubble.fbx"; var BUBBLE_SCRIPT = Script.resolvePath('bubble.js?' + randInt(0, 10000)); + var BUBBLE_USER_DATA_KEY = "BubbleKey"; var BUBBLE_INITIAL_DIMENSIONS = { x: 0.01, y: 0.01, @@ -109,6 +111,8 @@ return wandTipPosition }, addCollisionsToBubbleAfterCreation: function(bubble) { + + print('adding collisions to bubble' + bubble); Entities.editEntity(bubble, { collisionsWillMove: true }) @@ -130,12 +134,12 @@ var distance = Vec3.subtract(wandPosition, this.lastPosition); - var velocity = Vec3.multiply(distance,1/deltaTime); - - + var velocity = Vec3.multiply(distance, 1 / deltaTime); + + var velocityStrength = Vec3.length(velocity); - print('velocityStrength' +velocityStrength) - + print('velocityStrength' + velocityStrength) + // if (velocityStrength < VELOCITY_STRENGTH_LOWER_LIMIT) { // velocityStrength = 0 // } @@ -167,6 +171,9 @@ gravity: this.randomizeBubbleGravity() }); + //wait to make the bubbles collidable, so that they dont hit each other and the wand + Script.setTimeout(this.addCollisionsToBubbleAfterCreation(this.currentBubble), lifetime / 2); + //release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble this.createBubbleAtTipOfWand(); @@ -194,8 +201,10 @@ dimensions: dimensions }); }, - setBubbleOwner:function(bubble){ - setEntityCustomData(BUBBLE_USER_DATA_KEY, bubble, { avatarID: MyAvatar.sessionUUID }); + setBubbleOwner: function(bubble) { + setEntityCustomData(BUBBLE_USER_DATA_KEY, bubble, { + avatarID: MyAvatar.sessionUUID + }); }, createBubbleAtTipOfWand: function() { @@ -216,7 +225,7 @@ modelURL: BUBBLE_MODEL, position: wandTipPosition, dimensions: BUBBLE_INITIAL_DIMENSIONS, - collisionsWillMove: true, + collisionsWillMove: false, ignoreForCollisions: false, linearDamping: BUBBLE_LINEAR_DAMPING, shapeType: "sphere",