mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 10:37:56 +02:00
laser working
This commit is contained in:
parent
4bf1c36fd6
commit
d4c7b6b9b9
2 changed files with 96 additions and 57 deletions
|
@ -12,67 +12,106 @@
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
Script.include("../../libraries/utils.js");
|
||||||
|
Script.include("../../libraries/constants.js");
|
||||||
|
|
||||||
var scriptURL = Script.resolvePath('pistol.js');
|
var scriptURL = Script.resolvePath('pistol.js');
|
||||||
var _this;
|
var _this;
|
||||||
Pistol = function() {
|
Pistol = function() {
|
||||||
_this = this;
|
_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")
|
|
||||||
this.equipped = false;
|
this.equipped = false;
|
||||||
},
|
this.forceMultiplier = 1;
|
||||||
|
this.laserOffsets = {
|
||||||
|
y: .15
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
preload: function(entityID) {
|
Pistol.prototype = {
|
||||||
this.entityID = entityID;
|
|
||||||
print("INIT CONTROLLER MAPIING")
|
|
||||||
this.initControllerMapping();
|
|
||||||
},
|
|
||||||
|
|
||||||
triggerPress: function(hand, value) {
|
startEquip: function(id, params) {
|
||||||
print("TRIGGER PRESS");
|
this.equipped = true;
|
||||||
if (this.hand === hand && value === 1) {
|
this.hand = JSON.parse(params[0]);
|
||||||
//We are pulling trigger on the hand we have the gun in, so fire
|
Overlays.editOverlay(this.laser, {
|
||||||
this.fire();
|
visible: true
|
||||||
}
|
});
|
||||||
},
|
print("EQUIP")
|
||||||
|
},
|
||||||
|
|
||||||
fire: function() {
|
continueNearGrab: function() {
|
||||||
print("FIRE!");
|
if(!this.equipped) {
|
||||||
},
|
return;
|
||||||
|
}
|
||||||
|
this.updateLaser();
|
||||||
|
},
|
||||||
|
|
||||||
initControllerMapping: function() {
|
updateLaser: function() {
|
||||||
this.mapping = Controller.newMapping();
|
var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
|
||||||
this.mapping.from(Controller.Standard.LT).hysteresis(0.0, 0.5).to(function(value) {
|
var position = gunProps.position;
|
||||||
_this.triggerPress(0, value);
|
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.mapping.from(Controller.Standard.RT).hysteresis(0.0, 0.5).to(function(value) {
|
||||||
_this.triggerPress(1, value);
|
_this.triggerPress(1, value);
|
||||||
});
|
});
|
||||||
this.mapping.enable();
|
this.mapping.enable();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unload: function() {
|
unload: function() {
|
||||||
this.mapping.disable();
|
this.mapping.disable();
|
||||||
}
|
Overlays.deleteOverlay(this.laser); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// entity scripts always need to return a newly constructed object of our type
|
// entity scripts always need to return a newly constructed object of our type
|
||||||
print("TOOOss")
|
|
||||||
return new Pistol();
|
return new Pistol();
|
||||||
});
|
});
|
|
@ -11,15 +11,15 @@ var pistol = Entities.addEntity({
|
||||||
script: scriptURL,
|
script: scriptURL,
|
||||||
color: {red: 200, green: 0, blue: 20},
|
color: {red: 200, green: 0, blue: 20},
|
||||||
shapeType: 'box',
|
shapeType: 'box',
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true
|
||||||
userData: JSON.stringify({
|
// userData: JSON.stringify({
|
||||||
grabbableKey: {
|
// grabbableKey: {
|
||||||
spatialKey: {
|
// spatialKey: {
|
||||||
relativePosition: {x: 0, y: 0, z: 0},
|
// relativePosition: {x: 0, y: 0, z: 0},
|
||||||
relativeRotation: {x: 0, y: 0, z: 0, w: 1}
|
// relativeRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue