Firing works

This commit is contained in:
ericrius1 2015-11-18 14:32:49 -08:00
parent aed5629eca
commit 4bf1c36fd6
2 changed files with 40 additions and 5 deletions

View file

@ -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;
}

View file

@ -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