mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:10:49 +02:00
improve velocity calculations for wand
This commit is contained in:
parent
8a7798fcd7
commit
9a3a87eedf
3 changed files with 31 additions and 19 deletions
|
@ -71,9 +71,9 @@
|
||||||
position: position,
|
position: position,
|
||||||
lifetime: 0.1,
|
lifetime: 0.1,
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: 10,
|
x: 1,
|
||||||
y: 10,
|
y: 1,
|
||||||
z: 10
|
z: 1
|
||||||
},
|
},
|
||||||
emitVelocity: {
|
emitVelocity: {
|
||||||
x: 0.35,
|
x: 0.35,
|
||||||
|
@ -90,6 +90,7 @@
|
||||||
y: -0.1,
|
y: -0.1,
|
||||||
z: 0
|
z: 0
|
||||||
},
|
},
|
||||||
|
particleRadius:0.1,
|
||||||
alphaStart: 0.5,
|
alphaStart: 0.5,
|
||||||
alpha: 0.5,
|
alpha: 0.5,
|
||||||
alphaFinish: 0,
|
alphaFinish: 0,
|
||||||
|
|
|
@ -18,7 +18,7 @@ Script.include("../../libraries/utils.js");
|
||||||
var WAND_MODEL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx';
|
var WAND_MODEL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx';
|
||||||
var WAND_COLLISION_SHAPE = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj';
|
var WAND_COLLISION_SHAPE = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/collisionHull.obj';
|
||||||
var WAND_SCRIPT_URL = Script.resolvePath("wand.js");
|
var WAND_SCRIPT_URL = Script.resolvePath("wand.js");
|
||||||
//create the wand in front of the avatar
|
//create the wand in front of the avatar blahy
|
||||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {x: 0, y: 0.5, z: 0}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation())));
|
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {x: 0, y: 0.5, z: 0}), Vec3.multiply(0.5, Quat.getFront(Camera.getOrientation())));
|
||||||
|
|
||||||
var tablePosition = {
|
var tablePosition = {
|
||||||
|
@ -26,7 +26,7 @@ var tablePosition = {
|
||||||
y:495.63,
|
y:495.63,
|
||||||
z:506.25
|
z:506.25
|
||||||
}
|
}
|
||||||
|
print('test refresh')
|
||||||
var wand = Entities.addEntity({
|
var wand = Entities.addEntity({
|
||||||
name:'Bubble Wand',
|
name:'Bubble Wand',
|
||||||
type: "Model",
|
type: "Model",
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
Script.include("../../libraries/utils.js");
|
Script.include("../../libraries/utils.js");
|
||||||
|
|
||||||
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_INITIAL_DIMENSIONS = {
|
var BUBBLE_INITIAL_DIMENSIONS = {
|
||||||
x: 0.01,
|
x: 0.01,
|
||||||
|
@ -29,14 +29,14 @@
|
||||||
var BUBBLE_SIZE_MIN = 1;
|
var BUBBLE_SIZE_MIN = 1;
|
||||||
var BUBBLE_SIZE_MAX = 5;
|
var BUBBLE_SIZE_MAX = 5;
|
||||||
var BUBBLE_DIVISOR = 50;
|
var BUBBLE_DIVISOR = 50;
|
||||||
|
var BUBBLE_LINEAR_DAMPING = 0.4;
|
||||||
var GROWTH_FACTOR = 0.005;
|
var GROWTH_FACTOR = 0.005;
|
||||||
var SHRINK_FACTOR = 0.001;
|
var SHRINK_FACTOR = 0.001;
|
||||||
var SHRINK_LOWER_LIMIT = 0.02;
|
var SHRINK_LOWER_LIMIT = 0.02;
|
||||||
var WAND_TIP_OFFSET = 0.05;
|
var WAND_TIP_OFFSET = 0.05;
|
||||||
var VELOCITY_STRENGTH_LOWER_LIMIT = 0.01;
|
var VELOCITY_STRENGTH_LOWER_LIMIT = 0.01;
|
||||||
var VELOCITY_STRENGH_MAX = 10;
|
var VELOCITY_STRENGH_MAX = 10;
|
||||||
var VELOCITY_STRENGTH_MULTIPLIER = 100;
|
var VELOCITY_THRESHOLD = 0.5;
|
||||||
var VELOCITY_THRESHOLD = 1;
|
|
||||||
|
|
||||||
var _this;
|
var _this;
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = Entities.getEntityProperties(_this.entityID);
|
var properties = Entities.getEntityProperties(_this.entityID);
|
||||||
|
var dt = deltaTime;
|
||||||
_this.growBubbleWithWandVelocity(properties);
|
_this.growBubbleWithWandVelocity(properties, dt);
|
||||||
|
|
||||||
var wandTipPosition = _this.getWandTipPosition(properties);
|
var wandTipPosition = _this.getWandTipPosition(properties);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
|
|
||||||
//remove the current bubble when the wand is released
|
//remove the current bubble when the wand is released
|
||||||
Entities.deleteEntity(_this.currentBubble);
|
Entities.deleteEntity(_this.currentBubble);
|
||||||
_this.currentBubble=null
|
_this.currentBubble = null
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,27 +108,34 @@
|
||||||
this.wandTipPosition = wandTipPosition;
|
this.wandTipPosition = wandTipPosition;
|
||||||
return wandTipPosition
|
return wandTipPosition
|
||||||
},
|
},
|
||||||
|
addCollisionsToBubbleAfterCreation: function(bubble) {
|
||||||
|
Entities.editEntity(bubble, {
|
||||||
|
collisionsWillMove: true
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
randomizeBubbleGravity: function() {
|
randomizeBubbleGravity: function() {
|
||||||
|
|
||||||
var randomNumber = randInt(0, 3);
|
var randomNumber = randInt(0, 3);
|
||||||
var gravity= {
|
var gravity = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: -randomNumber / 10,
|
y: -randomNumber / 10,
|
||||||
z: 0
|
z: 0
|
||||||
}
|
}
|
||||||
return gravity
|
return gravity
|
||||||
},
|
},
|
||||||
growBubbleWithWandVelocity: function(properties) {
|
growBubbleWithWandVelocity: function(properties, deltaTime) {
|
||||||
|
|
||||||
var wandPosition = properties.position;
|
var wandPosition = properties.position;
|
||||||
var wandTipPosition = this.getWandTipPosition(properties)
|
var wandTipPosition = this.getWandTipPosition(properties)
|
||||||
|
|
||||||
|
|
||||||
var velocity = Vec3.subtract(wandPosition, this.lastPosition)
|
var distance = Vec3.subtract(wandPosition, this.lastPosition);
|
||||||
var velocityStrength = Vec3.length(velocity) * VELOCITY_STRENGTH_MULTIPLIER;
|
var velocity = Vec3.multiply(distance,1/deltaTime);
|
||||||
|
|
||||||
|
|
||||||
|
var velocityStrength = Vec3.length(velocity);
|
||||||
|
print('velocityStrength' +velocityStrength)
|
||||||
|
|
||||||
// if (velocityStrength < VELOCITY_STRENGTH_LOWER_LIMIT) {
|
// if (velocityStrength < VELOCITY_STRENGTH_LOWER_LIMIT) {
|
||||||
// velocityStrength = 0
|
// velocityStrength = 0
|
||||||
// }
|
// }
|
||||||
|
@ -187,6 +194,9 @@
|
||||||
dimensions: dimensions
|
dimensions: dimensions
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
setBubbleOwner:function(bubble){
|
||||||
|
setEntityCustomData(BUBBLE_USER_DATA_KEY, bubble, { avatarID: MyAvatar.sessionUUID });
|
||||||
|
},
|
||||||
createBubbleAtTipOfWand: function() {
|
createBubbleAtTipOfWand: function() {
|
||||||
|
|
||||||
//create a new bubble at the tip of the wand
|
//create a new bubble at the tip of the wand
|
||||||
|
@ -208,6 +218,7 @@
|
||||||
dimensions: BUBBLE_INITIAL_DIMENSIONS,
|
dimensions: BUBBLE_INITIAL_DIMENSIONS,
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true,
|
||||||
ignoreForCollisions: false,
|
ignoreForCollisions: false,
|
||||||
|
linearDamping: BUBBLE_LINEAR_DAMPING,
|
||||||
shapeType: "sphere",
|
shapeType: "sphere",
|
||||||
script: BUBBLE_SCRIPT,
|
script: BUBBLE_SCRIPT,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue