mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:08:47 +02:00
Merge pull request #6748 from ericrius1/gunFix
Fixing issue with muzzle flash and hit sparks being out of sync for pi…
This commit is contained in:
commit
a44a64d9c0
1 changed files with 77 additions and 55 deletions
|
@ -29,21 +29,14 @@
|
||||||
this.equipped = false;
|
this.equipped = false;
|
||||||
this.forceMultiplier = 1;
|
this.forceMultiplier = 1;
|
||||||
this.laserLength = 100;
|
this.laserLength = 100;
|
||||||
this.laserOffsets = {
|
|
||||||
y: .095
|
|
||||||
};
|
|
||||||
this.firingOffsets = {
|
|
||||||
z: 0.16
|
|
||||||
}
|
|
||||||
this.fireSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/GUN-SHOT2.raw");
|
this.fireSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/GUN-SHOT2.raw");
|
||||||
this.ricochetSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/Ricochet.L.wav");
|
this.ricochetSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/Ricochet.L.wav");
|
||||||
this.playRichochetSoundChance = 0.1;
|
this.playRichochetSoundChance = 0.1;
|
||||||
this.fireVolume = 0.2;
|
this.fireVolume = 0.2;
|
||||||
this.bulletForce = 10;
|
this.bulletForce = 10;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.showLaser = false;
|
this.showLaser = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pistol.prototype = {
|
Pistol.prototype = {
|
||||||
|
@ -58,20 +51,36 @@
|
||||||
if (!this.equipped) {
|
if (!this.equipped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.toggleWithTriggerPressure();
|
this.updateProps();
|
||||||
if (this.showLaser) {
|
if (this.showLaser) {
|
||||||
this.updateLaser();
|
this.updateLaser();
|
||||||
}
|
}
|
||||||
|
this.toggleWithTriggerPressure();
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
updateProps: function() {
|
||||||
|
var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
|
||||||
|
this.position = gunProps.position;
|
||||||
|
this.rotation = gunProps.rotation;
|
||||||
|
this.firingDirection = Quat.getFront(this.rotation);
|
||||||
|
var upVec = Quat.getUp(this.rotation);
|
||||||
|
this.barrelPoint = Vec3.sum(this.position, Vec3.multiply(upVec, this.laserOffsets.y));
|
||||||
|
this.laserTip = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.laserLength));
|
||||||
|
this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z))
|
||||||
|
var pickRay = {
|
||||||
|
origin: this.barrelPoint,
|
||||||
|
direction: this.firingDirection
|
||||||
|
};
|
||||||
},
|
},
|
||||||
toggleWithTriggerPressure: function() {
|
toggleWithTriggerPressure: function() {
|
||||||
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.hand]);
|
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.hand]);
|
||||||
|
|
||||||
if (this.triggerValue < RELOAD_THRESHOLD) {
|
if (this.triggerValue < RELOAD_THRESHOLD) {
|
||||||
// print('RELOAD');
|
|
||||||
this.canShoot = true;
|
this.canShoot = true;
|
||||||
}
|
}
|
||||||
if (this.canShoot === true && this.triggerValue === 1) {
|
if (this.canShoot === true && this.triggerValue === 1) {
|
||||||
// print('SHOOT');
|
|
||||||
this.fire();
|
this.fire();
|
||||||
this.canShoot = false;
|
this.canShoot = false;
|
||||||
}
|
}
|
||||||
|
@ -91,17 +100,10 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
updateLaser: function() {
|
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, this.laserLength));
|
|
||||||
this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z))
|
|
||||||
Overlays.editOverlay(this.laser, {
|
Overlays.editOverlay(this.laser, {
|
||||||
start: this.barrelPoint,
|
start: this.barrelPoint,
|
||||||
end: laserTip,
|
end: this.laserTip,
|
||||||
alpha: 1
|
alpha: 1
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -114,19 +116,6 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
preload: function(entityID) {
|
|
||||||
this.entityID = entityID;
|
|
||||||
// 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) {
|
triggerPress: function(hand, value) {
|
||||||
if (this.hand === hand && value === 1) {
|
if (this.hand === hand && value === 1) {
|
||||||
//We are pulling trigger on the hand we have the gun in, so fire
|
//We are pulling trigger on the hand we have the gun in, so fire
|
||||||
|
@ -135,15 +124,16 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
fire: function() {
|
fire: function() {
|
||||||
var pickRay = {
|
|
||||||
origin: this.barrelPoint,
|
|
||||||
direction: this.firingDirection
|
|
||||||
};
|
|
||||||
Audio.playSound(this.fireSound, {
|
Audio.playSound(this.fireSound, {
|
||||||
position: this.barrelPoint,
|
position: this.barrelPoint,
|
||||||
volume: this.fireVolume
|
volume: this.fireVolume
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var pickRay = {
|
||||||
|
origin: this.barrelPoint,
|
||||||
|
direction: this.firingDirection
|
||||||
|
};
|
||||||
this.createGunFireEffect(this.barrelPoint)
|
this.createGunFireEffect(this.barrelPoint)
|
||||||
var intersection = Entities.findRayIntersectionBlocking(pickRay, true);
|
var intersection = Entities.findRayIntersectionBlocking(pickRay, true);
|
||||||
if (intersection.intersects) {
|
if (intersection.intersects) {
|
||||||
|
@ -170,11 +160,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
createEntityHitEffect: function(position) {
|
createEntityHitEffect: function(position) {
|
||||||
var flash = Entities.addEntity({
|
var sparks = Entities.addEntity({
|
||||||
type: "ParticleEffect",
|
type: "ParticleEffect",
|
||||||
position: position,
|
position: position,
|
||||||
lifetime: 4,
|
lifetime: 4,
|
||||||
"name": "Flash Emitter",
|
"name": "Sparks Emitter",
|
||||||
"color": {
|
"color": {
|
||||||
red: 228,
|
red: 228,
|
||||||
green: 128,
|
green: 128,
|
||||||
|
@ -228,7 +218,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
Entities.editEntity(flash, {
|
Entities.editEntity(sparks, {
|
||||||
isEmitting: false
|
isEmitting: false
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
|
@ -261,11 +251,11 @@
|
||||||
"z": 0
|
"z": 0
|
||||||
},
|
},
|
||||||
"accelerationSpread": {
|
"accelerationSpread": {
|
||||||
"x": .2,
|
"x": 0.2,
|
||||||
"y": 0,
|
"y": 0,
|
||||||
"z": .2
|
"z": 0.2
|
||||||
},
|
},
|
||||||
"radiusSpread": .04,
|
"radiusSpread": 0.04,
|
||||||
"particleRadius": 0.07,
|
"particleRadius": 0.07,
|
||||||
"radiusStart": 0.07,
|
"radiusStart": 0.07,
|
||||||
"radiusFinish": 0.07,
|
"radiusFinish": 0.07,
|
||||||
|
@ -282,11 +272,46 @@
|
||||||
});
|
});
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
var flash = Entities.addEntity({
|
Entities.editEntity(this.flash, {
|
||||||
|
isEmitting: true
|
||||||
|
});
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
Entities.editEntity(_this.flash, {
|
||||||
|
isEmitting: false
|
||||||
|
});
|
||||||
|
}, 100)
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
preload: function(entityID) {
|
||||||
|
this.entityID = entityID;
|
||||||
|
this.laser = Overlays.addOverlay("line3d", {
|
||||||
|
start: ZERO_VECTOR,
|
||||||
|
end: ZERO_VECTOR,
|
||||||
|
color: COLORS.RED,
|
||||||
|
alpha: 1,
|
||||||
|
visible: true,
|
||||||
|
lineWidth: 2
|
||||||
|
});
|
||||||
|
this.laserOffsets = {
|
||||||
|
y: 0.095
|
||||||
|
};
|
||||||
|
this.firingOffsets = {
|
||||||
|
z: 0.16
|
||||||
|
}
|
||||||
|
var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']);
|
||||||
|
var position = gunProps.position;
|
||||||
|
var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0);
|
||||||
|
this.firingDirection = Quat.getFront(rotation);
|
||||||
|
var upVec = Quat.getUp(rotation);
|
||||||
|
this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y));
|
||||||
|
this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z))
|
||||||
|
|
||||||
|
this.flash = Entities.addEntity({
|
||||||
type: "ParticleEffect",
|
type: "ParticleEffect",
|
||||||
position: position,
|
position: this.barrelPoint,
|
||||||
lifetime: 4,
|
|
||||||
"name": "Muzzle Flash",
|
"name": "Muzzle Flash",
|
||||||
|
isEmitting: false,
|
||||||
"color": {
|
"color": {
|
||||||
red: 228,
|
red: 228,
|
||||||
green: 128,
|
green: 128,
|
||||||
|
@ -339,16 +364,13 @@
|
||||||
"textures": "http://ericrius1.github.io/PartiArt/assets/star.png"
|
"textures": "http://ericrius1.github.io/PartiArt/assets/star.png"
|
||||||
});
|
});
|
||||||
|
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
Entities.editEntity(flash, {
|
Entities.editEntity(_this.flash, {parentID: _this.entityID});
|
||||||
isEmitting: false
|
}, 500)
|
||||||
});
|
|
||||||
}, 100)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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
|
||||||
return new Pistol();
|
return new Pistol();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue