laser working

This commit is contained in:
ericrius1 2015-11-18 15:11:17 -08:00
parent 4bf1c36fd6
commit d4c7b6b9b9
2 changed files with 96 additions and 57 deletions

View file

@ -12,67 +12,106 @@
(function() {
Script.include("../../libraries/utils.js");
Script.include("../../libraries/constants.js");
var scriptURL = Script.resolvePath('pistol.js');
var _this;
Pistol = function() {
_this = this;
this.equipped = false;
this.forceMultiplier = 1;
};
Pistol.prototype = {
startEquip: function(id, params) {
print("HAND ", params[0]);
this.equipped = true;
this.hand = JSON.parse(params[0]);
},
unequip: function() {
print("UNEQUIP")
var scriptURL = Script.resolvePath('pistol.js');
var _this;
Pistol = function() {
_this = this;
this.equipped = false;
},
this.forceMultiplier = 1;
this.laserOffsets = {
y: .15
};
};
preload: function(entityID) {
this.entityID = entityID;
print("INIT CONTROLLER MAPIING")
this.initControllerMapping();
},
Pistol.prototype = {
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();
}
},
startEquip: function(id, params) {
this.equipped = true;
this.hand = JSON.parse(params[0]);
Overlays.editOverlay(this.laser, {
visible: true
});
print("EQUIP")
},
fire: function() {
print("FIRE!");
},
continueNearGrab: function() {
if(!this.equipped) {
return;
}
this.updateLaser();
},
initControllerMapping: function() {
this.mapping = Controller.newMapping();
this.mapping.from(Controller.Standard.LT).hysteresis(0.0, 0.5).to(function(value) {
_this.triggerPress(0, value);
});
updateLaser: function() {
var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
var position = gunProps.position;
var rotation = gunProps.rotation;
var direction = Quat.getFront(rotation);
var upVec = Quat.getUp(rotation);
position = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y));
var tip = Vec3.sum(position, Vec3.multiply(direction, 10));
Overlays.editOverlay(this.laser, {
start: position,
end: tip,
alpha: 1
});
},
unequip: function() {
print("UNEQUIP")
this.hand = null;
this.equipped = false;
Overlays.editOverlay(this.laser, {visible: false});
},
preload: function(entityID) {
this.entityID = entityID;
print("INIT CONTROLLER MAPIING")
this.initControllerMapping();
this.laser = Overlays.addOverlay("line3d", {
start: ZERO_VECTOR,
end: ZERO_VECTOR,
color: COLORS.RED,
alpha: 1,
visible: true,
lineWidth: 2
});
},
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();
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();
}
unload: function() {
this.mapping.disable();
Overlays.deleteOverlay(this.laser); }
};
// entity scripts always need to return a newly constructed object of our type
print("TOOOss")
return new Pistol();
});

View file

@ -11,15 +11,15 @@ var pistol = Entities.addEntity({
script: scriptURL,
color: {red: 200, green: 0, blue: 20},
shapeType: 'box',
collisionsWillMove: true,
userData: JSON.stringify({
grabbableKey: {
spatialKey: {
relativePosition: {x: 0, y: 0, z: 0},
relativeRotation: {x: 0, y: 0, z: 0, w: 1}
}
}
})
collisionsWillMove: true
// userData: JSON.stringify({
// grabbableKey: {
// spatialKey: {
// relativePosition: {x: 0, y: 0, z: 0},
// relativeRotation: {x: 0, y: 0, z: 0, w: 1}
// }
// }
// })
});