parenting visual to sound entity

This commit is contained in:
ericrius1 2016-03-08 18:30:27 -08:00
parent 9edc8aa5aa
commit deb2c5af63
3 changed files with 36 additions and 8 deletions

View file

@ -9,7 +9,7 @@
VRVJSoundEntity.prototype = {
playSound: function() {
_this.soundInjector = Audio.playSound(_this.clip, {position: _this.position, volume: 1.0});
// _this.soundInjector = Audio.playSound(_this.clip, {position: _this.position, volume: 1.0});
},
preload: function(entityID) {

View file

@ -1,25 +1,51 @@
(function() {
var _this;
Script.include("../libraries/utils.js");
var NULL_UUID = "{00000000-0000-0000-0000-000000000000}";
var ZERO_VEC = {x: 0, y: 0, z: 0};
VRVJVisualEntity = function() {
_this = this;
_this.SOUND_LOOP_NAME
_this.SOUND_LOOP_NAME = "VRVJ-Sound-Cartridge";
_this.SOUND_CARTRIDGE_SEARCH_RANGE = 0.1;
};
VRVJVisualEntity.prototype = {
releaseGrab: function() {
// search for nearby sound loop entities and if found, add it as a parent
_this.searchForNearbySoundLoops();
print("RELEASE GRAB")
// search for nearby sound loop entities and if found, add it as a parent
Script.setTimeout(function() {
_this.searchForNearbySoundLoops();
}, 100);
},
searchForNearbySoundLoops: function() {
_this.position = Entities.getEntityProperties(_this.entityID, "position").position;
var entities = Entities.findEntities(_this.position, _this.SOUND_CARTRIDGE_SEARCH_RANGE);
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var props = Entities.getEntityProperties(entity, ["name"]);
if (props.name.indexOf(_this.SOUND_LOOP_NAME) !== -1) {
// Need to set a timeout to wait for grab script to stop messing with entity
Entities.editEntity(_this.entityID, {
parentID: entity,
dynamic: false
});
Script.setTimeout(function() {
Entities.editEntity(_this.entityID, {dynamic: true});
}, 100);
return;
}
}
Entities.editEntity(_this.entityID, {
parentID: NULL_UUID
});
},
preload: function(entityID) {
print("YAAAA")
_this.entityID = entityID;
},

View file

@ -16,6 +16,7 @@ var soundEntity = Entities.addEntity({
color: {red: 200, green: 10, blue: 200},
position: center,
damping: 1,
angularDamping: 1,
dynamic: true,
script: SOUND_SCRIPT_URL,
userData: JSON.stringify({
@ -23,12 +24,13 @@ var soundEntity = Entities.addEntity({
})
});
var VISUAL_SCRIPT_URL = Script.resolvePath("VRVJVisualCartridgeEntityScript.js");
var VISUAL_SCRIPT_URL = Script.resolvePath("VRVJVisualCartridgeEntityScript.js?v1" + Math.random());
var visualEntity = Entities.addEntity({
type: "Sphere",
name: "VRVJ-Visual-Cartridge",
dimensions: {x: 0.1, y: 0.1, z: 0.1},
damping: 1,
angularDamping: 1,
color: {red: 0, green: 200, blue: 10},
dynamic: true,
position: Vec3.sum(center, {x: 0, y: 0.2, z: 0}),