From 9e250097348be1087b0859827fabceb7066e8781 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Mar 2016 11:19:30 -0700 Subject: [PATCH] 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} });