// // carnivalCoinBoxEntity.js // // Created by Thijs Wenker on 9/2/16. // Copyright 2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // (function() { var _this; var CoinBox = function() { _this = this; }; CoinBox.prototype = { entityID: null, preload: function(entityID) { _this.entityID = entityID; }, emitTriggerEvent: function() { print('emitting trigger event'); var parentEntity = Entities.getEntityProperties(_this.entityID, ['parentID']).parentID; Entities.callEntityMethod(parentEntity, 'coinBoxTrigger'); }, clickReleaseOnEntity: function(entityID, mouseEvent) { if (mouseEvent.isLeftButton) { _this.rezCoin(); } }, startFarTrigger: function(entityID, args) { _this.rezCoin(); }, startNearGrab: function(entityID, args) { _this.rezCoin(); }, rezCoin: function() { var properties = Entities.getEntityProperties(_this.entityID, ['position', 'rotation']); var direction = Quat.getFront(properties.rotation); Entities.addEntity({ collisionsWillMove: true, dimensions: { x: 0.1591, y: 0.1591, z: 0.0118 }, dynamic: true, gravity: { x: 0, y: -10, z: 0 }, velocity: Vec3.multiply(direction, -0.3), position: Vec3.sum(Vec3.multiply(direction, -0.1), properties.position), lifetime: 60, modelURL: Script.resolvePath('models/hfGamingToken.fbx'), name: "Carnival Coin", rotation: { w: 0.99490344524383545, x: -4.57763671875e-05, y: -0.10069429874420166, z: -1.52587890625e-05 }, script: Script.resolvePath('carnivalCoinEntity.js'), shapeType: "box", type: "Model", userData: JSON.stringify({ grabbableKey: { grabbable: true }, carnivalCoin: { value: 1 } }) }); } }; return new CoinBox(); });