use messages instead of hidden entities to disable beams

This commit is contained in:
James B. Pollack 2015-11-24 10:37:08 -08:00
parent fd26427390
commit 13e1042bfa
2 changed files with 51 additions and 104 deletions

View file

@ -1213,60 +1213,34 @@ mapping.from([Controller.Standard.LB]).peek().to(leftController.bumperPress);
Controller.enableMapping(MAPPING_NAME); Controller.enableMapping(MAPPING_NAME);
var handToDisable = 'none';
var beamDisabler;
function createBeamDisabler() {
var disablerProps = {
name: 'Hifi-Beam-Disabler',
type: 'Sphere',
dimensions: {
x: 0.1,
y: 0.1,
z: 0.1
},
color: {
red: 255,
green: 0,
blue: 0
},
visible: false,
position: MyAvatar.position,
ignoreForCollisions: true,
collisionsWillMove: false,
userData: JSON.stringify({
beamDisablerKey: {
handToDisable: 'none'
},
grabbableKey: {
grabbable: false
}
})
}
beamDisabler = Entities.addEntity(disablerProps)
}
function updateBeamDisablerPosition() {
Entities.editEntity(beamDisabler, {
position: MyAvatar.position
})
}
createBeamDisabler();
function update() { function update() {
updateBeamDisablerPosition(); if (handToDisable !== 0) {
var beamDisablerData = getEntityCustomData(BEAM_DISABLER_KEY, beamDisabler, {
handToDisable: 'none'
});
if (beamDisablerData.handToDisable !== 0) {
leftController.update(); leftController.update();
} }
if (beamDisablerData.handToDisable !== 1) { if (handToDisable !== 1) {
rightController.update(); rightController.update();
} }
} }
Messages.subscribe('Hifi-Beam-Disabler');
handleBeamDisablerMessages = function(channel, message,sender) {
print("got message:"+message+" on channel:" + channel + " from sender:"+sender);
handToDisable = message;
if(message==='left'){
handToDisable = 1;
}
if(message==='right'){
handToDisable = 0;
}
}
Messages.messageReceived.connect(handleBeamDisablerMessages);
function cleanup() { function cleanup() {
rightController.cleanup(); rightController.cleanup();
leftController.cleanup(); leftController.cleanup();

View file

@ -149,20 +149,9 @@
} }
this.isGrabbed = true; this.isGrabbed = true;
this.initialHand = this.hand; this.initialHand = this.hand;
Messages.sendMessage('Hifi-Beam-Disabler', this.initialHand);
var ids = Entities.findEntities(MyAvatar.position, 1);
for (var i in ids) {
var entityId = ids[i];
var foundProps = Entities.getEntityProperties(entityId);
if (foundProps.name == "Hifi-Beam-Disabler") {
print('FOUND THE BEAM DISABLER')
setEntityCustomData('beamDisablerKey', entityId, {
handToDisable: this.initialHand === 'left' ? 1 : 0
})
}
}
setEntityCustomData('grabbableKey', this.entityID, { setEntityCustomData('grabbableKey', this.entityID, {
grabbable: false, grabbable: false,
@ -214,21 +203,10 @@
}, },
releaseGrab: function() { releaseGrab: function() {
print('RELEASE GRAB EVENT') // print('RELEASE GRAB EVENT')
if (this.isGrabbed === true && this.hand === this.initialHand) { if (this.isGrabbed === true && this.hand === this.initialHand) {
var ids = Entities.findEntities(MyAvatar.position, 1);
for (var i in ids) {
var entityId = ids[i];
var foundProps = Entities.getEntityProperties(entityId);
if (foundProps.name == "Hifi-Beam-Disabler") {
print('FOUND THE BEAM DISABLER')
setEntityCustomData('beamDisablerKey', entityId, {
handToDisable: 'none'
})
}
}
Messages.sendMessage('Hifi-Beam-Disabler', "none")
this.isGrabbed = false; this.isGrabbed = false;
this.stringDrawn = false; this.stringDrawn = false;
@ -272,25 +250,25 @@
var makeArrowStick = function(entityA, entityB, collision) { var makeArrowStick = function(entityA, entityB, collision) {
Entities.editEntity(entityA, { Entities.editEntity(entityA, {
angularVelocity: { angularVelocity: {
x: 0, x: 0,
y: 0, y: 0,
z: 0 z: 0
}, },
velocity: { velocity: {
x: 0, x: 0,
y: 0, y: 0,
z: 0 z: 0
}, },
gravity: { gravity: {
x: 0, x: 0,
y: 0, y: 0,
z: 0 z: 0
}, },
position: collision.contactPoint, position: collision.contactPoint,
collisionsWillMove: false collisionsWillMove: false
}) })
print('ARROW COLLIDED WITH::' + entityB); // print('ARROW COLLIDED WITH::' + entityB);
Script.removeEventHandler(arrow, "collisionWithEntity", makeArrowStick) Script.removeEventHandler(arrow, "collisionWithEntity", makeArrowStick)
} }
@ -463,9 +441,8 @@
// print('TRIGGER VALUE:::' + this.triggerValue); // print('TRIGGER VALUE:::' + this.triggerValue);
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) { if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
print('TRIGGER VALUE??' + this.triggerValue) // firing the arrow
// firing the arrow // print('HIT RELEASE LOOP IN CHECK');
print('HIT RELEASE LOOP IN CHECK');
this.drawStrings(); this.drawStrings();
this.hasArrowNotched = false; this.hasArrowNotched = false;
@ -483,7 +460,7 @@
this.updateArrowPositionInNotch(); this.updateArrowPositionInNotch();
} else if (this.triggerValue > DRAW_STRING_THRESHOLD && this.stringDrawn === false) { } else if (this.triggerValue > DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
print('HIT START LOOP IN CHECK'); // print('HIT START LOOP IN CHECK');
this.arrow = this.createArrow(); this.arrow = this.createArrow();
this.playStringPullSound(); this.playStringPullSound();
@ -521,13 +498,12 @@
var handToNotch = Vec3.subtract(notchPosition, stringHandPosition); var handToNotch = Vec3.subtract(notchPosition, stringHandPosition);
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch); var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
var pullBackDistance = Vec3.length(handToNotch); var pullBackDistance = Vec3.length(handToNotch);
// this.changeStringPullSoundVolume(pullBackDistance); // this.changeStringPullSoundVolume(pullBackDistance);
if(pullBackDistance>0.6){ if (pullBackDistance > 0.6) {
pullBackDistance = 0.6; pullBackDistance = 0.6;
} }
@ -539,7 +515,7 @@
var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET); var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET);
var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset); var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset);
//we draw strings to the rear of the arrow //we draw strings to the rear of the arrow
this.setArrowRearPosition(finalArrowPosition, arrowRotation); this.setArrowRearPosition(finalArrowPosition, arrowRotation);
//if we're not shooting, we're updating the arrow's orientation //if we're not shooting, we're updating the arrow's orientation
@ -564,7 +540,7 @@
//make the arrow physical, give it gravity, a lifetime, and set our velocity //make the arrow physical, give it gravity, a lifetime, and set our velocity
var arrowProperties = { var arrowProperties = {
collisionsWillMove: true, collisionsWillMove: true,
ignoreForCollisions:false, ignoreForCollisions: false,
velocity: releaseVelocity, velocity: releaseVelocity,
gravity: ARROW_GRAVITY, gravity: ARROW_GRAVITY,
lifetime: 10, lifetime: 10,
@ -582,9 +558,6 @@
visible: true visible: true
}); });
var afterVelocity = Entities.getEntityProperties(this.arrow).velocity;
print('VELOCITY AFTER RELEASE:::' + JSON.stringify(afterVelocity))
} }
}, },