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,6 +12,8 @@
(function() {
Script.include("../../libraries/utils.js");
Script.include("../../libraries/constants.js");
var scriptURL = Script.resolvePath('pistol.js');
var _this;
@ -19,25 +21,63 @@
_this = this;
this.equipped = false;
this.forceMultiplier = 1;
this.laserOffsets = {
y: .15
};
};
Pistol.prototype = {
startEquip: function(id, params) {
print("HAND ", params[0]);
this.equipped = true;
this.hand = JSON.parse(params[0]);
Overlays.editOverlay(this.laser, {
visible: true
});
print("EQUIP")
},
continueNearGrab: function() {
if(!this.equipped) {
return;
}
this.updateLaser();
},
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) {
@ -68,11 +108,10 @@
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}
// }
// }
// })
});