From 8d4001e54ea536b89dc99df3af466820be749804 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 10:57:54 -0700 Subject: [PATCH] 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