mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
add beam disabler
This commit is contained in:
parent
3f4dee80d9
commit
aa832311f5
3 changed files with 111 additions and 47 deletions
|
@ -109,13 +109,13 @@ var GRABBABLE_PROPERTIES = [
|
||||||
|
|
||||||
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
||||||
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
||||||
|
var BEAM_DISABLER_KEY = 'beamDisablerKey'
|
||||||
|
|
||||||
var DEFAULT_GRABBABLE_DATA = {
|
var DEFAULT_GRABBABLE_DATA = {
|
||||||
grabbable: true,
|
grabbable: true,
|
||||||
invertSolidWhileHeld: false
|
invertSolidWhileHeld: false
|
||||||
};
|
};
|
||||||
|
|
||||||
var disabledHand = 'none';
|
|
||||||
|
|
||||||
// states for the state machine
|
// states for the state machine
|
||||||
var STATE_OFF = 0;
|
var STATE_OFF = 0;
|
||||||
|
@ -411,11 +411,6 @@ function MyController(hand) {
|
||||||
this.search = function() {
|
this.search = function() {
|
||||||
this.grabbedEntity = null;
|
this.grabbedEntity = null;
|
||||||
|
|
||||||
// if this hand is the one that's disabled, we don't want to search for anything at all
|
|
||||||
if (this.hand === disabledHand) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.state == STATE_SEARCHING ? this.triggerSmoothedReleased() : this.bumperReleased()) {
|
if (this.state == STATE_SEARCHING ? this.triggerSmoothedReleased() : this.bumperReleased()) {
|
||||||
this.setState(STATE_RELEASE);
|
this.setState(STATE_RELEASE);
|
||||||
return;
|
return;
|
||||||
|
@ -460,17 +455,7 @@ function MyController(hand) {
|
||||||
// the ray is intersecting something we can move.
|
// the ray is intersecting something we can move.
|
||||||
var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection);
|
var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection);
|
||||||
|
|
||||||
//this code will disabled the beam for the opposite hand of the one that grabbed it if the entity says so
|
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA);
|
||||||
if (grabbableData["turnOffOppositeBeam"]===true) {
|
|
||||||
if (this.hand === RIGHT_HAND) {
|
|
||||||
disabledHand = LEFT_HAND;
|
|
||||||
} else {
|
|
||||||
disabledHand = RIGHT_HAND;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
disabledHand = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (intersection.properties.name == "Grab Debug Entity") {
|
if (intersection.properties.name == "Grab Debug Entity") {
|
||||||
continue;
|
continue;
|
||||||
|
@ -758,21 +743,8 @@ function MyController(hand) {
|
||||||
|
|
||||||
this.nearGrabbing = function() {
|
this.nearGrabbing = function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
print('HAND IN NEAR GRAB:::' + this.hand)
|
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||||
|
|
||||||
var turnOffOtherHand = grabbableData["turnOffOtherHand"];
|
|
||||||
print('TURN OFF OTHER HAND??' + turnOffOtherHand);
|
|
||||||
if (turnOffOtherHand === 'left' && this.hand === 1) {
|
|
||||||
print('IGNORE RIGHT')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (turnOffOtherHand === 'right' && this.hand === 0) {
|
|
||||||
print('IGNORE LEFT')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
|
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
|
||||||
this.setState(STATE_RELEASE);
|
this.setState(STATE_RELEASE);
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "releaseGrab");
|
Entities.callEntityMethod(this.grabbedEntity, "releaseGrab");
|
||||||
|
@ -1121,10 +1093,6 @@ function MyController(hand) {
|
||||||
|
|
||||||
this.release = function() {
|
this.release = function() {
|
||||||
|
|
||||||
if (this.hand !== disabledHand) {
|
|
||||||
//release the disabled hand when we let go with the main one
|
|
||||||
disabledHand = 'none';
|
|
||||||
}
|
|
||||||
this.lineOff();
|
this.lineOff();
|
||||||
|
|
||||||
if (this.grabbedEntity !== null) {
|
if (this.grabbedEntity !== null) {
|
||||||
|
@ -1246,14 +1214,64 @@ mapping.from([Controller.Standard.LB]).peek().to(leftController.bumperPress);
|
||||||
Controller.enableMapping(MAPPING_NAME);
|
Controller.enableMapping(MAPPING_NAME);
|
||||||
|
|
||||||
|
|
||||||
|
var beamDisabler;
|
||||||
|
|
||||||
|
function createBeamDisabler() {
|
||||||
|
print('CREATING DISABLER')
|
||||||
|
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: true,
|
||||||
|
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() {
|
||||||
rightController.update();
|
updateBeamDisablerPosition();
|
||||||
leftController.update();
|
var beamDisablerData = getEntityCustomData(BEAM_DISABLER_KEY, beamDisabler, {
|
||||||
|
handToDisable: 'none'
|
||||||
|
});
|
||||||
|
if (beamDisablerData.handToDisable !== 0) {
|
||||||
|
leftController.update();
|
||||||
|
}
|
||||||
|
if (beamDisablerData.handToDisable !== 1) {
|
||||||
|
rightController.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
rightController.cleanup();
|
rightController.cleanup();
|
||||||
leftController.cleanup();
|
leftController.cleanup();
|
||||||
|
Entities.deleteEntity(beamDisabler);
|
||||||
Controller.disableMapping(MAPPING_NAME);
|
Controller.disableMapping(MAPPING_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var USE_DEBOUNCE = false;
|
||||||
function interval() {
|
function interval() {
|
||||||
var lastTime = new Date().getTime();
|
var lastTime = new Date().getTime();
|
||||||
|
|
||||||
|
@ -111,13 +112,13 @@
|
||||||
blue: 255
|
blue: 255
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
sinceLastUpdate:0,
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
this.stringPullSound = SoundCache.getSound(STRING_PULL_SOUND_URL);
|
this.stringPullSound = SoundCache.getSound(STRING_PULL_SOUND_URL);
|
||||||
this.shootArrowSound = SoundCache.getSound(SHOOT_ARROW_SOUND_URL);
|
this.shootArrowSound = SoundCache.getSound(SHOOT_ARROW_SOUND_URL);
|
||||||
this.arrowHitSound = SoundCache.getSound(ARROW_HIT_SOUND_URL);
|
this.arrowHitSound = SoundCache.getSound(ARROW_HIT_SOUND_URL);
|
||||||
this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL);
|
this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL);
|
||||||
this.arrowWhizzSound = SoundCache.getSound(ARROW_WHIZZ_SOUND_URL);
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -145,11 +146,25 @@
|
||||||
if (this.isGrabbed === true) {
|
if (this.isGrabbed === true) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isGrabbed = true;
|
this.isGrabbed = true;
|
||||||
this.initialHand = this.hand;
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setEntityCustomData('grabbableKey', this.entityID, {
|
setEntityCustomData('grabbableKey', this.entityID, {
|
||||||
turnOffOtherHand: this.initialHand,
|
grabbable: false,
|
||||||
invertSolidWhileHeld: true,
|
invertSolidWhileHeld: true,
|
||||||
turnOffOppositeBeam: true,
|
turnOffOppositeBeam: true,
|
||||||
spatialKey: BOW_SPATIAL_KEY
|
spatialKey: BOW_SPATIAL_KEY
|
||||||
|
@ -157,7 +172,19 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
continueNearGrab: function() {
|
continueNearGrab: function() {
|
||||||
this.deltaTime = checkInterval();
|
|
||||||
|
//debounce during debugging -- maybe we're updating too fast?
|
||||||
|
if (USE_DEBOUNCE === true) {
|
||||||
|
this.deltaTime = checkInterval();
|
||||||
|
this.sinceLastUpdate = this.sinceLastUpdate + this.deltaTime;
|
||||||
|
|
||||||
|
if (this.sinceLastUpdate > 60) {
|
||||||
|
this.sinceLastUpdate = 0;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.bowProperties = Entities.getEntityProperties(this.entityID);
|
this.bowProperties = Entities.getEntityProperties(this.entityID);
|
||||||
|
|
||||||
//create a string across the bow when we pick it up
|
//create a string across the bow when we pick it up
|
||||||
|
@ -189,13 +216,27 @@
|
||||||
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'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.isGrabbed = false;
|
this.isGrabbed = false;
|
||||||
this.stringDrawn = false;
|
this.stringDrawn = false;
|
||||||
this.deleteStrings();
|
this.deleteStrings();
|
||||||
setEntityCustomData('grabbableKey', this.entityID, {
|
setEntityCustomData('grabbableKey', this.entityID, {
|
||||||
turnOffOtherHand: false,
|
grabbable: true,
|
||||||
|
turnOffOppositeBeam: true,
|
||||||
invertSolidWhileHeld: true,
|
invertSolidWhileHeld: true,
|
||||||
turnOffOppositebBam: true,
|
|
||||||
spatialKey: BOW_SPATIAL_KEY
|
spatialKey: BOW_SPATIAL_KEY
|
||||||
});
|
});
|
||||||
Entities.deleteEntity(this.preNotchString);
|
Entities.deleteEntity(this.preNotchString);
|
||||||
|
@ -414,15 +455,19 @@
|
||||||
// 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) {
|
||||||
// firing the arrow
|
print('TRIGGER VALUE??' + this.triggerValue)
|
||||||
|
// firing the arrow
|
||||||
print('HIT RELEASE LOOP IN CHECK');
|
print('HIT RELEASE LOOP IN CHECK');
|
||||||
this.updateArrowPositionInNotch(true);
|
|
||||||
|
this.drawStrings();
|
||||||
this.hasArrowNotched = false;
|
this.hasArrowNotched = false;
|
||||||
this.aiming = false;
|
this.aiming = false;
|
||||||
this.stringDrawn = false;
|
this.stringDrawn = false;
|
||||||
|
this.updateArrowPositionInNotch(true);
|
||||||
|
|
||||||
|
|
||||||
} else if (this.triggerValue > DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
} else if (this.triggerValue > DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||||
// print('HIT CONTINUE LOOP IN CHECK')
|
print('HIT CONTINUE LOOP IN CHECK')
|
||||||
//continuing to aim the arrow
|
//continuing to aim the arrow
|
||||||
|
|
||||||
this.aiming = true;
|
this.aiming = true;
|
||||||
|
@ -454,7 +499,6 @@
|
||||||
|
|
||||||
updateArrowPositionInNotch: function(shouldReleaseArrow) {
|
updateArrowPositionInNotch: function(shouldReleaseArrow) {
|
||||||
var bowProperties = Entities.getEntityProperties(this.entityID);
|
var bowProperties = Entities.getEntityProperties(this.entityID);
|
||||||
|
|
||||||
//set the notch that the arrow should go through
|
//set the notch that the arrow should go through
|
||||||
var frontVector = Quat.getFront(bowProperties.rotation);
|
var frontVector = Quat.getFront(bowProperties.rotation);
|
||||||
var notchVectorForward = Vec3.multiply(frontVector, NOTCH_OFFSET_FORWARD);
|
var notchVectorForward = Vec3.multiply(frontVector, NOTCH_OFFSET_FORWARD);
|
||||||
|
@ -494,6 +538,7 @@
|
||||||
|
|
||||||
//shoot the arrow
|
//shoot the arrow
|
||||||
if (shouldReleaseArrow === true) {
|
if (shouldReleaseArrow === true) {
|
||||||
|
var arrowProperties = Entities.getEntityProperties(this.arrow);
|
||||||
|
|
||||||
//scale the shot strength by the distance you've pulled the arrow back and set its release velocity to be in the direction of the v
|
//scale the shot strength by the distance you've pulled the arrow back and set its release velocity to be in the direction of the v
|
||||||
var arrowForce = this.scaleArrowShotStrength(pullBackDistance);
|
var arrowForce = this.scaleArrowShotStrength(pullBackDistance);
|
||||||
|
@ -504,7 +549,9 @@
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true,
|
||||||
velocity: releaseVelocity,
|
velocity: releaseVelocity,
|
||||||
gravity: ARROW_GRAVITY,
|
gravity: ARROW_GRAVITY,
|
||||||
lifetime: 10
|
lifetime: 10,
|
||||||
|
position:notchPosition,
|
||||||
|
rotation:arrowRotation
|
||||||
};
|
};
|
||||||
|
|
||||||
//actually shoot the arrow and play its sound
|
//actually shoot the arrow and play its sound
|
||||||
|
|
|
@ -46,8 +46,7 @@ var bow = Entities.addEntity({
|
||||||
script: SCRIPT_URL,
|
script: SCRIPT_URL,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
grabbableKey: {
|
grabbableKey: {
|
||||||
turnOffOtherHand:false,
|
turnOffOppositeBeam:true,
|
||||||
turnOffOppositebeam:true,
|
|
||||||
invertSolidWhileHeld: true,
|
invertSolidWhileHeld: true,
|
||||||
spatialKey: {
|
spatialKey: {
|
||||||
relativePosition: {
|
relativePosition: {
|
||||||
|
|
Loading…
Reference in a new issue