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);
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();
var handToDisable = 'none';
function update() {
updateBeamDisablerPosition();
var beamDisablerData = getEntityCustomData(BEAM_DISABLER_KEY, beamDisabler, {
handToDisable: 'none'
});
if (beamDisablerData.handToDisable !== 0) {
if (handToDisable !== 0) {
leftController.update();
}
if (beamDisablerData.handToDisable !== 1) {
if (handToDisable !== 1) {
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() {
rightController.cleanup();
leftController.cleanup();

View file

@ -149,20 +149,9 @@
}
this.isGrabbed = true;
this.initialHand = this.hand;
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
})
}
}
Messages.sendMessage('Hifi-Beam-Disabler', this.initialHand);
setEntityCustomData('grabbableKey', this.entityID, {
grabbable: false,
@ -214,21 +203,10 @@
},
releaseGrab: function() {
print('RELEASE GRAB EVENT')
// print('RELEASE GRAB EVENT')
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.stringDrawn = false;
@ -290,7 +268,7 @@
position: collision.contactPoint,
collisionsWillMove: false
})
print('ARROW COLLIDED WITH::' + entityB);
// print('ARROW COLLIDED WITH::' + entityB);
Script.removeEventHandler(arrow, "collisionWithEntity", makeArrowStick)
}
@ -463,9 +441,8 @@
// print('TRIGGER VALUE:::' + this.triggerValue);
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
print('TRIGGER VALUE??' + this.triggerValue)
// firing the arrow
print('HIT RELEASE LOOP IN CHECK');
// print('HIT RELEASE LOOP IN CHECK');
this.drawStrings();
this.hasArrowNotched = false;
@ -483,7 +460,7 @@
this.updateArrowPositionInNotch();
} 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.playStringPullSound();
@ -523,7 +500,6 @@
var pullBackDistance = Vec3.length(handToNotch);
// this.changeStringPullSoundVolume(pullBackDistance);
@ -582,9 +558,6 @@
visible: true
});
var afterVelocity = Entities.getEntityProperties(this.arrow).velocity;
print('VELOCITY AFTER RELEASE:::' + JSON.stringify(afterVelocity))
}
},