50 lines
2 KiB
JavaScript
50 lines
2 KiB
JavaScript
(function() {
|
|
var MIN_DISTANCE = 0.5;
|
|
var wasNearHead = false;
|
|
var phoneyBoxProperties = null;
|
|
|
|
this.startNearGrab = function(entityID, args) {
|
|
print("starting PhoneyNearGrab!!");
|
|
wasNearHead = false;
|
|
phoneyBoxProperties = null;
|
|
Entities.findEntities(MyAvatar.position, 32000).forEach(function(entity) {
|
|
if (Entities.getEntityProperties(entity, 'name').name === 'PhoneyBox') {
|
|
phoneyBoxProperties = Entities.getEntityProperties(entity, ['rotation', 'position']);
|
|
print("PhoneyBox found at " + JSON.stringify(phoneyBoxProperties.position));
|
|
}
|
|
});
|
|
|
|
};
|
|
this.continueNearGrab = function(entityID, args) {
|
|
if (phoneyBoxProperties === null) {
|
|
return;
|
|
}
|
|
var avatarHeadPosition = MyAvatar.getJointPosition(MyAvatar.getJointIndex('Head'));
|
|
var phoneyPosition = Entities.getEntityProperties(entityID, 'position').position;
|
|
var isNearHead = Vec3.distance(avatarHeadPosition, phoneyPosition) < MIN_DISTANCE;
|
|
if (isNearHead === wasNearHead) {
|
|
return;
|
|
}
|
|
wasNearHead = isNearHead;
|
|
if (isNearHead) {
|
|
MyAvatar.customListenPosition = phoneyBoxProperties.position;
|
|
MyAvatar.customListenOrientation = phoneyBoxProperties.rotation;
|
|
MyAvatar.audioListenerMode = MyAvatar.audioListenerModeCustom;
|
|
print('Calling in from ' + JSON.stringify(phoneyBoxProperties.position));
|
|
} else {
|
|
MyAvatar.audioListenerMode = MyAvatar.audioListenerModeHead;
|
|
print('Stopped listening.');
|
|
}
|
|
};
|
|
this.releaseGrab = function(entityID, args) {
|
|
if (wasNearHead) {
|
|
MyAvatar.audioListenerMode = MyAvatar.audioListenerModeHead;
|
|
wasNearHead = null;
|
|
}
|
|
};
|
|
this.unload = function(entityID) {
|
|
if (wasNearHead) {
|
|
MyAvatar.audioListenerMode = MyAvatar.audioListenerModeHead;
|
|
}
|
|
};
|
|
});
|