mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:56:44 +02:00
added effects back in
This commit is contained in:
parent
53f75e305a
commit
1c9f94f3c0
2 changed files with 282 additions and 91 deletions
|
@ -300,7 +300,7 @@ function createBloodSplatter(position) {
|
||||||
type: "ParticleEffect",
|
type: "ParticleEffect",
|
||||||
position: position,
|
position: position,
|
||||||
lifetime: 4,
|
lifetime: 4,
|
||||||
"name": "Blood SPlatter",
|
"name": "Blood Splatter",
|
||||||
"color": {
|
"color": {
|
||||||
red: 230,
|
red: 230,
|
||||||
green: 2,
|
green: 2,
|
||||||
|
|
|
@ -12,111 +12,302 @@
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
Script.include("../../libraries/utils.js");
|
Script.include("../../libraries/utils.js");
|
||||||
Script.include("../../libraries/constants.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.equipped = false;
|
||||||
this.forceMultiplier = 1;
|
this.forceMultiplier = 1;
|
||||||
this.laserOffsets = {
|
this.laserOffsets = {
|
||||||
y: .15,
|
y: .15,
|
||||||
};
|
|
||||||
this.firingOffsets = {
|
|
||||||
z: 0.3
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
this.firingOffsets = {
|
||||||
|
z: 0.3
|
||||||
|
}
|
||||||
|
this.fireSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/GUN-SHOT2.raw");
|
||||||
|
this.fireVolume = 0.5;
|
||||||
|
};
|
||||||
|
|
||||||
Pistol.prototype = {
|
Pistol.prototype = {
|
||||||
|
|
||||||
startEquip: function(id, params) {
|
startEquip: function(id, params) {
|
||||||
this.equipped = true;
|
this.equipped = true;
|
||||||
this.hand = JSON.parse(params[0]);
|
this.hand = JSON.parse(params[0]);
|
||||||
Overlays.editOverlay(this.laser, {
|
Overlays.editOverlay(this.laser, {
|
||||||
visible: true
|
visible: true
|
||||||
});
|
});
|
||||||
print("EQUIP")
|
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;
|
||||||
|
this.firingDirection = Quat.getFront(rotation);
|
||||||
|
var upVec = Quat.getUp(rotation);
|
||||||
|
this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y));
|
||||||
|
var laserTip = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, 10));
|
||||||
|
this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z))
|
||||||
|
Overlays.editOverlay(this.laser, {
|
||||||
|
start: this.barrelPoint,
|
||||||
|
end: laserTip,
|
||||||
|
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() {
|
||||||
|
var pickRay = {
|
||||||
|
origin: this.barrelPoint,
|
||||||
|
direction: this.firingDirection
|
||||||
|
};
|
||||||
|
Audio.playSound(this.fireSound, {
|
||||||
|
position: this.barrelPoint,
|
||||||
|
volume: this.fireVolume
|
||||||
|
});
|
||||||
|
this.createGunFireEffect(this.barrelPoint)
|
||||||
|
var intersection = Entities.findRayIntersectionBlocking(pickRay, true);
|
||||||
|
if (intersection.intersects) {
|
||||||
|
this.createEntityHitEffect(intersection.intersection);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
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();
|
||||||
|
Overlays.deleteOverlay(this.laser);
|
||||||
|
},
|
||||||
|
|
||||||
|
createEntityHitEffect: function(position) {
|
||||||
|
var flash = Entities.addEntity({
|
||||||
|
type: "ParticleEffect",
|
||||||
|
position: position,
|
||||||
|
lifetime: 4,
|
||||||
|
"name": "Flash Emitter",
|
||||||
|
"color": {
|
||||||
|
red: 228,
|
||||||
|
green: 128,
|
||||||
|
blue: 12
|
||||||
},
|
},
|
||||||
|
"maxParticles": 1000,
|
||||||
continueNearGrab: function() {
|
"lifespan": 0.15,
|
||||||
if(!this.equipped) {
|
"emitRate": 1000,
|
||||||
return;
|
"emitSpeed": 1,
|
||||||
}
|
"speedSpread": 0,
|
||||||
this.updateLaser();
|
"emitOrientation": {
|
||||||
|
"x": -0.4,
|
||||||
|
"y": 1,
|
||||||
|
"z": -0.2,
|
||||||
|
"w": 0.7071068286895752
|
||||||
},
|
},
|
||||||
|
"emitDimensions": {
|
||||||
updateLaser: function() {
|
"x": 0,
|
||||||
var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
|
"y": 0,
|
||||||
var position = gunProps.position;
|
"z": 0
|
||||||
var rotation = gunProps.rotation;
|
|
||||||
this.firingDirection = Quat.getFront(rotation);
|
|
||||||
var upVec = Quat.getUp(rotation);
|
|
||||||
this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y));
|
|
||||||
var laserTip = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, 10));
|
|
||||||
this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z))
|
|
||||||
Overlays.editOverlay(this.laser, {
|
|
||||||
start: this.barrelPoint,
|
|
||||||
end: laserTip,
|
|
||||||
alpha: 1
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
"polarStart": 0,
|
||||||
unequip: function() {
|
"polarFinish": Math.PI,
|
||||||
print("UNEQUIP")
|
"azimuthStart": -3.1415927410125732,
|
||||||
this.hand = null;
|
"azimuthFinish": 2,
|
||||||
this.equipped = false;
|
"emitAcceleration": {
|
||||||
Overlays.editOverlay(this.laser, {visible: false});
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
},
|
},
|
||||||
|
"accelerationSpread": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"particleRadius": 0.03,
|
||||||
|
"radiusSpread": 0.02,
|
||||||
|
"radiusStart": 0.02,
|
||||||
|
"radiusFinish": 0.03,
|
||||||
|
"colorSpread": {
|
||||||
|
red: 100,
|
||||||
|
green: 100,
|
||||||
|
blue: 20
|
||||||
|
},
|
||||||
|
"alpha": 1,
|
||||||
|
"alphaSpread": 0,
|
||||||
|
"alphaStart": 0,
|
||||||
|
"alphaFinish": 0,
|
||||||
|
"additiveBlending": true,
|
||||||
|
"textures": "http://ericrius1.github.io/PartiArt/assets/star.png"
|
||||||
|
});
|
||||||
|
|
||||||
preload: function(entityID) {
|
Script.setTimeout(function() {
|
||||||
this.entityID = entityID;
|
Entities.editEntity(flash, {
|
||||||
print("INIT CONTROLLER MAPIING")
|
isEmitting: false
|
||||||
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() {
|
|
||||||
var pickRay = {origin: this.barrelPoint, direction: this.firingDirection};
|
|
||||||
var intersection = Entities.findRayIntersectionBlocking(pickRay, true);
|
|
||||||
if(intersection.intersects) {
|
|
||||||
print('intersection!');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
initControllerMapping: function() {
|
|
||||||
this.mapping = Controller.newMapping();
|
|
||||||
this.mapping.from(Controller.Standard.LT).hysteresis(0.0, 0.5).to(function(value) {
|
|
||||||
_this.triggerPress(0, value);
|
|
||||||
});
|
});
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
this.mapping.from(Controller.Standard.RT).hysteresis(0.0, 0.5).to(function(value) {
|
createGunFireEffect: function(position) {
|
||||||
_this.triggerPress(1, value);
|
var smoke = Entities.addEntity({
|
||||||
|
type: "ParticleEffect",
|
||||||
|
position: position,
|
||||||
|
lifetime: 1,
|
||||||
|
"name": "Smoke Hit Emitter",
|
||||||
|
"maxParticles": 1000,
|
||||||
|
"lifespan": 4,
|
||||||
|
"emitRate": 20,
|
||||||
|
emitSpeed: 0,
|
||||||
|
"speedSpread": 0,
|
||||||
|
"emitDimensions": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"polarStart": 0,
|
||||||
|
"polarFinish": 0,
|
||||||
|
"azimuthStart": -3.1415927410125732,
|
||||||
|
"azimuthFinish": 3.14,
|
||||||
|
"emitAcceleration": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0.5,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"accelerationSpread": {
|
||||||
|
"x": .2,
|
||||||
|
"y": 0,
|
||||||
|
"z": .2
|
||||||
|
},
|
||||||
|
"radiusSpread": .04,
|
||||||
|
"particleRadius": 0.07,
|
||||||
|
"radiusStart": 0.07,
|
||||||
|
"radiusFinish": 0.07,
|
||||||
|
"alpha": 0.7,
|
||||||
|
"alphaSpread": 0,
|
||||||
|
"alphaStart": 0,
|
||||||
|
"alphaFinish": 0,
|
||||||
|
"additiveBlending": 0,
|
||||||
|
"textures": "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png"
|
||||||
|
});
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
Entities.editEntity(smoke, {
|
||||||
|
isEmitting: false
|
||||||
});
|
});
|
||||||
this.mapping.enable();
|
}, 100);
|
||||||
|
|
||||||
},
|
var flash = Entities.addEntity({
|
||||||
|
type: "ParticleEffect",
|
||||||
|
position: position,
|
||||||
|
lifetime: 4,
|
||||||
|
"name": "Muzzle Flash",
|
||||||
|
"color": {
|
||||||
|
red: 228,
|
||||||
|
green: 128,
|
||||||
|
blue: 12
|
||||||
|
},
|
||||||
|
"maxParticles": 1000,
|
||||||
|
"lifespan": 0.1,
|
||||||
|
"emitRate": 1000,
|
||||||
|
"emitSpeed": 0.5,
|
||||||
|
"speedSpread": 0,
|
||||||
|
"emitOrientation": {
|
||||||
|
"x": -0.4,
|
||||||
|
"y": 1,
|
||||||
|
"z": -0.2,
|
||||||
|
"w": 0.7071068286895752
|
||||||
|
},
|
||||||
|
"emitDimensions": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"polarStart": 0,
|
||||||
|
"polarFinish": Math.PI,
|
||||||
|
"azimuthStart": -3.1415927410125732,
|
||||||
|
"azimuthFinish": 2,
|
||||||
|
"emitAcceleration": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"accelerationSpread": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0,
|
||||||
|
"z": 0
|
||||||
|
},
|
||||||
|
"particleRadius": 0.05,
|
||||||
|
"radiusSpread": 0.01,
|
||||||
|
"radiusStart": 0.05,
|
||||||
|
"radiusFinish": 0.05,
|
||||||
|
"colorSpread": {
|
||||||
|
red: 100,
|
||||||
|
green: 100,
|
||||||
|
blue: 20
|
||||||
|
},
|
||||||
|
"alpha": 1,
|
||||||
|
"alphaSpread": 0,
|
||||||
|
"alphaStart": 0,
|
||||||
|
"alphaFinish": 0,
|
||||||
|
"additiveBlending": true,
|
||||||
|
"textures": "http://ericrius1.github.io/PartiArt/assets/star.png"
|
||||||
|
});
|
||||||
|
|
||||||
unload: function() {
|
Script.setTimeout(function() {
|
||||||
this.mapping.disable();
|
Entities.editEntity(flash, {
|
||||||
Overlays.deleteOverlay(this.laser); }
|
isEmitting: false
|
||||||
|
});
|
||||||
|
}, 100)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue