From 8d4001e54ea536b89dc99df3af466820be749804 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 10:57:54 -0700 Subject: [PATCH 1/7] only tip cow after its done colliding --- examples/cows/cowEntityScript.js | 42 ++++++++++++++++++++++++++++++++ examples/cows/cowSpawner.js | 40 ++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 examples/cows/cowEntityScript.js create mode 100644 examples/cows/cowSpawner.js diff --git a/examples/cows/cowEntityScript.js b/examples/cows/cowEntityScript.js new file mode 100644 index 0000000000..161cd2af66 --- /dev/null +++ b/examples/cows/cowEntityScript.js @@ -0,0 +1,42 @@ +(function() { + Script.include("../libraries/utils.js"); + + var _this = this; + + + + this.preload = function(entityID) { + print("EBL Preload!!"); + _this.entityID = entityID; + _this.mooSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/moo.wav") + _this.mooSoundOptions = {volume: 0.7, loop: false}; + } + + this.collisionWithEntity = function(myID, otherID, collisionInfo) { + print("EBL COLLISION WITH ENTITY!"); + this.untipCow(); + } + + this.untipCow = function() { + // keep yaw but reset pitch and roll + var cowProps = Entities.getEntityProperties(_this.entityID, ["rotation", "position"]); + var eulerRotation = Quat.safeEulerAngles(cowProps.rotation); + eulerRotation.x = 0; + eulerRotation.z = 0; + var newRotation = Quat.fromVec3Degrees(eulerRotation); + var newRotation = Entities.editEntity(_this.entityID, { + rotation: newRotation + }); + + + _this.mooSoundOptions.position = cowProps.position; + if (!_this.soundInjector) { + _this.soundInjector = Audio.playSound(_this.mooSound, _this.mooSoundOptions); + } else { + _this.soundInjector.setOptions(_this.mooSoundOptions); + _this.soundInjector.restart(); + } + } + + +}); \ No newline at end of file diff --git a/examples/cows/cowSpawner.js b/examples/cows/cowSpawner.js new file mode 100644 index 0000000000..6a23a6b5e8 --- /dev/null +++ b/examples/cows/cowSpawner.js @@ -0,0 +1,40 @@ + var orientation = MyAvatar.orientation; + orientation = Quat.safeEulerAngles(orientation); + orientation.x = 0; + orientation = Quat.fromVec3Degrees(orientation); + var center = Vec3.sum(MyAvatar.getHeadPosition(), Vec3.multiply(2, Quat.getFront(orientation))); + + + var SCRIPT_URL = Script.resolvePath("cowEntityScript.js?v1" + Math.random()); + var cow = Entities.addEntity({ + type: "Model", + modelURL: "http://hifi-content.s3.amazonaws.com/DomainContent/production/cow/newMooCow.fbx", + name: "playa_model_throwinCow", + position: center, + animation: { + currentFrame: 278, + running: true, + url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Playa/newMooCow.fbx" + }, + dimensions: { + x: 0.739, + y: 1.613, + z: 2.529 + }, + dynamic: true, + gravity: { + x: 0, + y: -5, + z: 0 + }, + shapeType: "box", + script: SCRIPT_URL, + userData: "{\"grabbableKey\":{\"grabbable\":true}}" + }); + + + function cleanup() { + Entities.deleteEntity(cow); + } + + Script.scriptEnding.connect(cleanup); \ No newline at end of file From 9e250097348be1087b0859827fabceb7066e8781 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 11:19:30 -0700 Subject: [PATCH 2/7] untipping cow --- examples/cows/cowEntityScript.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/cows/cowEntityScript.js b/examples/cows/cowEntityScript.js index 161cd2af66..2f91aa1ac0 100644 --- a/examples/cows/cowEntityScript.js +++ b/examples/cows/cowEntityScript.js @@ -2,7 +2,7 @@ Script.include("../libraries/utils.js"); var _this = this; - + _this.COLLISION_COOLDOWN_TIME = 5000; this.preload = function(entityID) { @@ -10,22 +10,35 @@ _this.entityID = entityID; _this.mooSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/moo.wav") _this.mooSoundOptions = {volume: 0.7, loop: false}; + _this.timeSinceLastCollision = 0; + _this.shouldUntipCow = true; } this.collisionWithEntity = function(myID, otherID, collisionInfo) { print("EBL COLLISION WITH ENTITY!"); - this.untipCow(); + if(_this.shouldUntipCow) { + Script.setTimeout(function() { + _this.untipCow(); + _this.shouldUntipCow = true; + }, _this.COLLISION_COOLDOWN_TIME); + } + + _this.shouldUntipCow = false; + } this.untipCow = function() { + print("EBL UNTIP COW"); // keep yaw but reset pitch and roll var cowProps = Entities.getEntityProperties(_this.entityID, ["rotation", "position"]); var eulerRotation = Quat.safeEulerAngles(cowProps.rotation); eulerRotation.x = 0; eulerRotation.z = 0; var newRotation = Quat.fromVec3Degrees(eulerRotation); - var newRotation = Entities.editEntity(_this.entityID, { - rotation: newRotation + Entities.editEntity(_this.entityID, { + rotation: newRotation, + velocity: {x: 0, y: 0, z: 0}, + angularVelocity: {x: 0, y: 0, z:0} }); From cc92294d16efc60dbf1d221b96168a74303017e5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 11:21:08 -0700 Subject: [PATCH 3/7] removed vr vj stuff --- .../VR-VJ/VRVJSoundCartridgeEntityScript.js | 35 ----------- .../VR-VJ/VRVJVisualCartridgeEntityScript.js | 58 ------------------- examples/VR-VJ/cartridgesSpawner.js | 49 ---------------- 3 files changed, 142 deletions(-) delete mode 100644 examples/VR-VJ/VRVJSoundCartridgeEntityScript.js delete mode 100644 examples/VR-VJ/VRVJVisualCartridgeEntityScript.js delete mode 100644 examples/VR-VJ/cartridgesSpawner.js diff --git a/examples/VR-VJ/VRVJSoundCartridgeEntityScript.js b/examples/VR-VJ/VRVJSoundCartridgeEntityScript.js deleted file mode 100644 index c8e106c468..0000000000 --- a/examples/VR-VJ/VRVJSoundCartridgeEntityScript.js +++ /dev/null @@ -1,35 +0,0 @@ - -(function() { - var _this; - Script.include("../libraries/utils.js"); - VRVJSoundEntity = function() { - _this = this; - - }; - - VRVJSoundEntity.prototype = { - playSound: function() { - // _this.soundInjector = Audio.playSound(_this.clip, {position: _this.position, volume: 1.0}); - }, - - preload: function(entityID) { - _this.entityID = entityID; - _this.position = Entities.getEntityProperties(_this.entityID, "position").position; - _this.userData = getEntityUserData(_this.entityID); - _this.clip = SoundCache.getSound(_this.userData.soundURL); - - }, - - unload: function() { - if (_this.soundInjector) { - _this.soundInjector.stop(); - delete _this.soundInjector; - } - } - - - }; - - // entity scripts always need to return a newly constructed object of our type - return new VRVJSoundEntity(); -}); \ No newline at end of file diff --git a/examples/VR-VJ/VRVJVisualCartridgeEntityScript.js b/examples/VR-VJ/VRVJVisualCartridgeEntityScript.js deleted file mode 100644 index a37b830a58..0000000000 --- a/examples/VR-VJ/VRVJVisualCartridgeEntityScript.js +++ /dev/null @@ -1,58 +0,0 @@ -(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 = "VRVJ-Sound-Cartridge"; - _this.SOUND_CARTRIDGE_SEARCH_RANGE = 0.1; - - }; - - VRVJVisualEntity.prototype = { - - releaseGrab: function() { - 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", "color"]); - 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, velocity: ZERO_VEC, color: props.color}); - }, 100); - return; - } - - } - Entities.editEntity(_this.entityID, { - parentID: NULL_UUID, - color: _this.originalColor - }); - }, - - preload: function(entityID) { - print("YAAAA") - _this.entityID = entityID; - _this.originalColor = Entities.getEntityProperties(_this.entityID, "color").color; - - }, - }; - - // entity scripts always need to return a newly constructed object of our type - return new VRVJVisualEntity(); -}); \ No newline at end of file diff --git a/examples/VR-VJ/cartridgesSpawner.js b/examples/VR-VJ/cartridgesSpawner.js deleted file mode 100644 index 3ce8fd953a..0000000000 --- a/examples/VR-VJ/cartridgesSpawner.js +++ /dev/null @@ -1,49 +0,0 @@ - var orientation = MyAvatar.orientation; - orientation = Quat.safeEulerAngles(orientation); - orientation.x = 0; - orientation = Quat.fromVec3Degrees(orientation); - var center = Vec3.sum(MyAvatar.getHeadPosition(), Vec3.multiply(2, Quat.getFront(orientation))); - - -Script.include("../libraries/utils.js"); - -var SOUND_SCRIPT_URL = Script.resolvePath("VRVJSoundCartridgeEntityScript.js"); -var SOUND_CARTRIDGE_NAME = "VRVJ-Sound-Cartridge"; -var soundEntity = Entities.addEntity({ - type: "Box", - name: SOUND_CARTRIDGE_NAME, - dimensions: {x: 0.1, y: 0.1, z: 0.1}, - color: {red: 200, green: 10, blue: 200}, - position: center, - damping: 1, - angularDamping: 1, - dynamic: true, - script: SOUND_SCRIPT_URL, - userData: JSON.stringify({ - soundURL: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/VRVJ/Synth-MarchToWar.wav", - }) -}); - -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.subtract(center, {x: 0, y: 0.2, z: 0}), - script: VISUAL_SCRIPT_URL -}); -Script.setTimeout(function() { - // Wait for sounds to load - Entities.callEntityMethod(soundEntity, "playSound"); -}, 1000) - -function cleanup() { - Entities.deleteEntity(soundEntity); - Entities.deleteEntity(visualEntity); -} - -Script.scriptEnding.connect(cleanup); \ No newline at end of file From 721b94044164fe446c325a6d0687857af8f91d0c Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 12:52:53 -0700 Subject: [PATCH 4/7] untip cow --- examples/cows/cowEntityScript.js | 17 +++++++++++++++-- examples/cows/cowSpawner.js | 13 +++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/examples/cows/cowEntityScript.js b/examples/cows/cowEntityScript.js index 2f91aa1ac0..5f93c2e56d 100644 --- a/examples/cows/cowEntityScript.js +++ b/examples/cows/cowEntityScript.js @@ -1,3 +1,18 @@ + // +// cowEntityScript.js +// examples/cows +// +// Created by Eric Levin on 3/25/16 +// Copyright 2016 High Fidelity, Inc. +// +// This entity script handles the logic for untipping a cow after it collides with something +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + + (function() { Script.include("../libraries/utils.js"); @@ -15,7 +30,6 @@ } this.collisionWithEntity = function(myID, otherID, collisionInfo) { - print("EBL COLLISION WITH ENTITY!"); if(_this.shouldUntipCow) { Script.setTimeout(function() { _this.untipCow(); @@ -28,7 +42,6 @@ } this.untipCow = function() { - print("EBL UNTIP COW"); // keep yaw but reset pitch and roll var cowProps = Entities.getEntityProperties(_this.entityID, ["rotation", "position"]); var eulerRotation = Quat.safeEulerAngles(cowProps.rotation); diff --git a/examples/cows/cowSpawner.js b/examples/cows/cowSpawner.js index 6a23a6b5e8..294b8b66a5 100644 --- a/examples/cows/cowSpawner.js +++ b/examples/cows/cowSpawner.js @@ -1,3 +1,16 @@ + // +// cowSpawner.js +// examples/cows +// +// Created by Eric Levin on 3/25/16 +// Copyright 2016 High Fidelity, Inc. +// +// This spawns a cow which will untip itself +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + var orientation = MyAvatar.orientation; orientation = Quat.safeEulerAngles(orientation); orientation.x = 0; From be499747f2b9e70d9a2a6c4ce49cd4e459ffc122 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 12:54:06 -0700 Subject: [PATCH 5/7] no bust caching" --- examples/cows/cowSpawner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cows/cowSpawner.js b/examples/cows/cowSpawner.js index 294b8b66a5..a1f7caee4b 100644 --- a/examples/cows/cowSpawner.js +++ b/examples/cows/cowSpawner.js @@ -18,7 +18,7 @@ var center = Vec3.sum(MyAvatar.getHeadPosition(), Vec3.multiply(2, Quat.getFront(orientation))); - var SCRIPT_URL = Script.resolvePath("cowEntityScript.js?v1" + Math.random()); + var SCRIPT_URL = Script.resolvePath("cowEntityScript.js?"); var cow = Entities.addEntity({ type: "Model", modelURL: "http://hifi-content.s3.amazonaws.com/DomainContent/production/cow/newMooCow.fbx", From e0f843d6ebf4c0b3282eb7e43ef7d8d62ae32a91 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 31 Mar 2016 18:49:51 -0700 Subject: [PATCH 6/7] removes extra space --- examples/cows/cowEntityScript.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cows/cowEntityScript.js b/examples/cows/cowEntityScript.js index 5f93c2e56d..1150be6b36 100644 --- a/examples/cows/cowEntityScript.js +++ b/examples/cows/cowEntityScript.js @@ -1,4 +1,4 @@ - // + // cowEntityScript.js // examples/cows // @@ -65,4 +65,4 @@ } -}); \ No newline at end of file +}); From 8176852503e5793ea0860b83c0ff8d4756f23c02 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 31 Mar 2016 18:50:24 -0700 Subject: [PATCH 7/7] removed extra space --- examples/cows/cowSpawner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cows/cowSpawner.js b/examples/cows/cowSpawner.js index a1f7caee4b..7ff59b2e38 100644 --- a/examples/cows/cowSpawner.js +++ b/examples/cows/cowSpawner.js @@ -1,4 +1,4 @@ - // + // cowSpawner.js // examples/cows // @@ -50,4 +50,4 @@ Entities.deleteEntity(cow); } - Script.scriptEnding.connect(cleanup); \ No newline at end of file + Script.scriptEnding.connect(cleanup);