diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 0bf8693391..3acb911d2d 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -773,7 +773,7 @@ function MyController(hand) { this.setState(STATE_CONTINUE_NEAR_GRABBING); } else { // equipping - Entities.callEntityMethod(this.grabbedEntity, "equip", [JSON.stringify(this.hand)]); + Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); this.setState(STATE_CONTINUE_EQUIP_BD); } @@ -808,7 +808,7 @@ function MyController(hand) { } if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.bumperSqueezed()) { this.setState(STATE_CONTINUE_EQUIP_BD); - Entities.callEntityMethod(this.grabbedEntity, "equip", [JSON.stringify(this.hand)]); + Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); return; } diff --git a/examples/weapons/pistol/pistol.js b/examples/weapons/pistol/pistol.js index 63fb3c4006..26d7a9b551 100644 --- a/examples/weapons/pistol/pistol.js +++ b/examples/weapons/pistol/pistol.js @@ -12,6 +12,7 @@ (function() { + var scriptURL = Script.resolvePath('pistol.js'); var _this; Pistol = function() { @@ -22,19 +23,53 @@ Pistol.prototype = { - equip: function() { + startEquip: function(id, params) { + print("HAND ", params[0]); this.equipped = true; - print("EQUIP") + this.hand = JSON.parse(params[0]); }, unequip: function() { - this.equipped = true; + print("UNEQUIP") + this.equipped = false; }, preload: function(entityID) { this.entityID = entityID; + print("INIT CONTROLLER MAPIING") + this.initControllerMapping(); }, + triggerPress: function(hand, value) { + print("TRIGGER PRESS"); + if (this.hand === hand && value === 1) { + //We are pulling trigger on the hand we have the gun in, so fire + this.fire(); + } + }, + + fire: function() { + print("FIRE!"); + }, + + initControllerMapping: function() { + this.mapping = Controller.newMapping(); + this.mapping.from(Controller.Standard.LT).hysteresis(0.0, 0.5).to(function(value) { + _this.triggerPress(0, value); + }); + + + this.mapping.from(Controller.Standard.RT).hysteresis(0.0, 0.5).to(function(value) { + _this.triggerPress(1, value); + }); + this.mapping.enable(); + + }, + + unload: function() { + this.mapping.disable(); + } + }; // entity scripts always need to return a newly constructed object of our type