lightsaber immediately turns off on release

This commit is contained in:
ericrius1 2015-12-21 13:30:52 -08:00
parent 4110630d1f
commit cabc47e7a9
2 changed files with 76 additions and 56 deletions

View file

@ -27,7 +27,16 @@
ArcBall.prototype = { ArcBall.prototype = {
isGrabbed: false, isGrabbed: false,
startNearGrab: function() { startDistanceGrab: function() {
this.searchForNearbyArcBalls();
},
startFarGrab: function() {
this.searchForNearbyArcBalls();
},
searchForNearbyArcBalls: function() {
//Search for nearby balls and create an arc to it if one is found //Search for nearby balls and create an arc to it if one is found
var position = Entities.getEntityProperties(this.entityID, "position").position var position = Entities.getEntityProperties(this.entityID, "position").position
var entities = Entities.findEntities(position, 10); var entities = Entities.findEntities(position, 10);
@ -36,12 +45,13 @@
if (props.name === "Arc Ball" && JSON.stringify(_this.entityID) !== JSON.stringify(entity)) { if (props.name === "Arc Ball" && JSON.stringify(_this.entityID) !== JSON.stringify(entity)) {
_this.target = entity; _this.target = entity;
_this.createBeam(position, props.position); _this.createBeam(position, props.position);
} }
}); });
}, },
createBeam: function(startPosition, endPosition) { createBeam: function(startPosition, endPosition) {
// Creates particle arc from start position to end position // Creates particle arc from start position to end position
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
var sourceToTargetVec = Vec3.subtract(endPosition, startPosition); var sourceToTargetVec = Vec3.subtract(endPosition, startPosition);
@ -50,61 +60,65 @@
var color = this.colorPalette[randInt(0, this.colorPalette.length)]; var color = this.colorPalette[randInt(0, this.colorPalette.length)];
var props = { var props = {
type: "ParticleEffect", type: "ParticleEffect",
name: "Particle Arc", name: "Particle Arc",
parentID: this.entityID, parentID: this.entityID,
parentJointIndex: -1, parentJointIndex: -1,
// position: startPosition, // position: startPosition,
isEmitting: true, isEmitting: true,
colorStart: color, colorStart: color,
color: { color: {
red: 200, red: 200,
green: 200, green: 200,
blue: 255 blue: 255
}, },
colorFinish: color, colorFinish: color,
maxParticles: 100000, maxParticles: 100000,
lifespan: 2, lifespan: 2,
emitRate: 1000, emitRate: 1000,
emitOrientation: emitOrientation, emitOrientation: emitOrientation,
emitSpeed: .1, emitSpeed: .1,
speedSpread: 0.02, speedSpread: 0.02,
emitDimensions: { emitDimensions: {
x: .01, x: .01,
y: .01, y: .01,
z: .01 z: .01
}, },
polarStart: 0, polarStart: 0,
polarFinish: .0, polarFinish: .0,
azimuthStart: .02, azimuthStart: .02,
azimuthFinish: .01, azimuthFinish: .01,
emitAcceleration: { emitAcceleration: {
x: 0, x: 0,
y: 0, y: 0,
z: 0 z: 0
}, },
accelerationSpread: { accelerationSpread: {
x: .00, x: .00,
y: .00, y: .00,
z: .00 z: .00
}, },
radiusStart: 0.01, radiusStart: 0.01,
radiusFinish: 0.005, radiusFinish: 0.005,
radiusSpread: .005, radiusSpread: .005,
alpha: 0.5, alpha: 0.5,
alphaSpread: .1, alphaSpread: .1,
alphaStart: 0.5, alphaStart: 0.5,
alphaFinish: 0.0, alphaFinish: 0.0,
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png", textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png",
emitterShouldTrail: true emitterShouldTrail: true
} }
this.particleArc = Entities.addEntity(props); this.particleArc = Entities.addEntity(props);
}, },
updateBeam: function(startPosition) { updateBeam: function() {
if(!this.target) {
return;
}
var startPosition = Entities.getEntityProperties(this.entityID, "position").position;
var targetPosition = Entities.getEntityProperties(this.target, "position").position; var targetPosition = Entities.getEntityProperties(this.target, "position").position;
print("TARGET position " + JSON.stringify(this.target));
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
var sourceToTargetVec = Vec3.subtract(targetPosition, startPosition); var sourceToTargetVec = Vec3.subtract(targetPosition, startPosition);
var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec); var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec);
@ -115,14 +129,18 @@
}, },
continueNearGrab: function() { continueNearGrab: function() {
var startPosition = Entities.getEntityProperties(this.entityID, "position").position; this.updateBeam();
this.updateBeam(startPosition); },
continueDistanceGrab: function() {
this.updateBeam();
}, },
releaseGrab: function() { releaseGrab: function() {
Entities.editEntity(this.particleArc, { Entities.editEntity(this.particleArc, {
isEmitting: false isEmitting: false
}); });
this.target = null;
}, },
unload: function() { unload: function() {

View file

@ -31,12 +31,14 @@
startNearGrab: function() { startNearGrab: function() {
Entities.editEntity(this.beam, { Entities.editEntity(this.beam, {
isEmitting: true isEmitting: true,
visible: true
}); });
}, },
releaseGrab: function() { releaseGrab: function() {
Entities.editEntity(this.beam, { Entities.editEntity(this.beam, {
visible: false,
isEmitting: false isEmitting: false
}); });
}, },