collision timeouts

This commit is contained in:
James B. Pollack 2015-09-18 10:41:44 -07:00
parent 9a3a87eedf
commit 15ea9219d6
2 changed files with 30 additions and 11 deletions

View file

@ -16,6 +16,8 @@
var BUBBLE_PARTICLE_TEXTURE = "http://hifi-public.s3.amazonaws.com/james/bubblewand/textures/bubble_particle.png" 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 = { BUBBLE_PARTICLE_COLOR = {
red: 0, red: 0,
green: 40, green: 40,
@ -44,8 +46,16 @@
this.unload = function(entityID) { this.unload = function(entityID) {
Script.update.disconnect(this.update); 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. var defaultGrabData = {
// _this.createBurstParticles(); avatarId: null
};
var bubbleCreator = getEntityCustomData(BUBBLE_USER_DATA_KEY, entityID, defaultGrabData);
if (bubbleCreator === MyAvatar.sessionUUID) {
this.createBurstParticles();
}
}; };
@ -90,7 +100,7 @@
y: -0.1, y: -0.1,
z: 0 z: 0
}, },
particleRadius:0.1, particleRadius: 0.1,
alphaStart: 0.5, alphaStart: 0.5,
alpha: 0.5, alpha: 0.5,
alphaFinish: 0, alphaFinish: 0,

View file

@ -10,6 +10,7 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
(function() { (function() {
Script.include("../../utilities.js"); 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_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_SCRIPT = Script.resolvePath('bubble.js?' + randInt(0, 10000));
var BUBBLE_USER_DATA_KEY = "BubbleKey";
var BUBBLE_INITIAL_DIMENSIONS = { var BUBBLE_INITIAL_DIMENSIONS = {
x: 0.01, x: 0.01,
y: 0.01, y: 0.01,
@ -109,6 +111,8 @@
return wandTipPosition return wandTipPosition
}, },
addCollisionsToBubbleAfterCreation: function(bubble) { addCollisionsToBubbleAfterCreation: function(bubble) {
print('adding collisions to bubble' + bubble);
Entities.editEntity(bubble, { Entities.editEntity(bubble, {
collisionsWillMove: true collisionsWillMove: true
}) })
@ -130,12 +134,12 @@
var distance = Vec3.subtract(wandPosition, this.lastPosition); 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); var velocityStrength = Vec3.length(velocity);
print('velocityStrength' +velocityStrength) print('velocityStrength' + velocityStrength)
// if (velocityStrength < VELOCITY_STRENGTH_LOWER_LIMIT) { // if (velocityStrength < VELOCITY_STRENGTH_LOWER_LIMIT) {
// velocityStrength = 0 // velocityStrength = 0
// } // }
@ -167,6 +171,9 @@
gravity: this.randomizeBubbleGravity() 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 //release the bubble -- when we create a new bubble, it will carry on and this update loop will affect the new bubble
this.createBubbleAtTipOfWand(); this.createBubbleAtTipOfWand();
@ -194,8 +201,10 @@
dimensions: dimensions dimensions: dimensions
}); });
}, },
setBubbleOwner:function(bubble){ setBubbleOwner: function(bubble) {
setEntityCustomData(BUBBLE_USER_DATA_KEY, bubble, { avatarID: MyAvatar.sessionUUID }); setEntityCustomData(BUBBLE_USER_DATA_KEY, bubble, {
avatarID: MyAvatar.sessionUUID
});
}, },
createBubbleAtTipOfWand: function() { createBubbleAtTipOfWand: function() {
@ -216,7 +225,7 @@
modelURL: BUBBLE_MODEL, modelURL: BUBBLE_MODEL,
position: wandTipPosition, position: wandTipPosition,
dimensions: BUBBLE_INITIAL_DIMENSIONS, dimensions: BUBBLE_INITIAL_DIMENSIONS,
collisionsWillMove: true, collisionsWillMove: false,
ignoreForCollisions: false, ignoreForCollisions: false,
linearDamping: BUBBLE_LINEAR_DAMPING, linearDamping: BUBBLE_LINEAR_DAMPING,
shapeType: "sphere", shapeType: "sphere",