First version of ping pong gun

This commit is contained in:
James Pollack 2015-09-30 11:21:51 -07:00
parent ecad7f34f6
commit 8bdf428f41
2 changed files with 20 additions and 35 deletions

View file

@ -39,6 +39,6 @@ var pingPongGun = Entities.addEntity({
}); });
function cleanUp() { function cleanUp() {
Entities.deleteEntity(pingPongGun); Entities.deleteEntity(pingPongGun);
} }
Script.scriptEnding.connect(cleanup) Script.scriptEnding.connect(cleanUp);

View file

@ -15,23 +15,14 @@
var SHOOTING_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/flashlight_on.wav'; var SHOOTING_SOUND_URL = 'http://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/flashlight_on.wav';
// this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember
// our this object, so we can access it in cases where we're called without a this (like in the case of various global signals)
function PingPongGun() { function PingPongGun() {
return; return;
} }
//if the trigger value goes below this value, reload the gun. //if the trigger value goes below this value, reload the gun.
var RELOAD_THRESHOLD = 0.7; var RELOAD_THRESHOLD = 0.95;
var GUN_TIP_OFFSET = 0.095; var GUN_TIP_FWD_OFFSET = -0.056;
// // Evaluate the world light entity positions and orientations from the model ones var GUN_TIP_UP_OFFSET = 0.001;
// function evalLightWorldTransform(modelPos, modelRot) {
// return {
// p: Vec3.sum(modelPos, Vec3.multiplyQbyV(modelRot, MODEL_LIGHT_POSITION)),
// q: Quat.multiply(modelRot, MODEL_LIGHT_ROTATION)
// };
// }
PingPongGun.prototype = { PingPongGun.prototype = {
hand: null, hand: null,
@ -64,7 +55,7 @@
}, },
releaseGrab: function() { releaseGrab: function() {
this.canShoot = false;
}, },
checkTriggerPressure: function(gunHand) { checkTriggerPressure: function(gunHand) {
@ -75,7 +66,7 @@
this.triggerValue = Controller.getActionValue(handClick); this.triggerValue = Controller.getActionValue(handClick);
if (this.triggerValue < RELOAD_THRESHOLD) { if (this.triggerValue < RELOAD_THRESHOLD) {
print('RELOAD'); // print('RELOAD');
this.canShoot = true; this.canShoot = true;
} else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) { } else if (this.triggerValue >= RELOAD_THRESHOLD && this.canShoot === true) {
var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); var gunProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
@ -85,10 +76,10 @@
return; return;
}, },
shootBall: function(gunProperties, triggerValue) { shootBall: function(gunProperties) {
var forwardVec = Quat.getFront(Quat.multiply(gunProperties.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0))); var forwardVec = Quat.getFront(Quat.multiply(gunProperties.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0)));
// forwardVec = Vec3.normalize(forwardVec); forwardVec = Vec3.normalize(forwardVec);
forwardVec = Vec3.multiply(forwardVec, 2);
var properties = { var properties = {
type: 'Sphere', type: 'Sphere',
color: { color: {
@ -114,42 +105,36 @@
velocity: forwardVec, velocity: forwardVec,
lifetime: 10 lifetime: 10
}; };
var pingPongBall = Entities.addEntity(properties);
var audioOptions = { Entities.addEntity(properties);
position: gunProperties.position
}
this.playSoundAtCurrentPosition(gunProperties.position); this.playSoundAtCurrentPosition(gunProperties.position);
}, },
playSoundAtCurrentPosition: function(position) { playSoundAtCurrentPosition: function(position) {
var audioProperties = { var audioProperties = {
volume: 0.25, volume: 0.25,
position: position position: position
}; };
Audio.playSound(this.SHOOTING_SOUND, audioProperties); Audio.playSound(this.SHOOTING_SOUND, audioProperties);
}, },
getGunTipPosition: function(properties) { getGunTipPosition: function(properties) {
//the tip of the gun is going to be in a different place than the center, so we move in space relative to the model to find that position //the tip of the gun is going to be in a different place than the center, so we move in space relative to the model to find that position
var frontVector = Quat.getFront(properties.rotation); var frontVector = Quat.getRight(properties.rotation);
var frontOffset = Vec3.multiply(frontVector, GUN_TIP_OFFSET); var frontOffset = Vec3.multiply(frontVector, GUN_TIP_FWD_OFFSET);
var upVector = Quat.getRight(properties.rotation);
var upOffset = Vec3.multiply(upVector, GUN_TIP_UP_OFFSET);
var gunTipPosition = Vec3.sum(properties.position, frontOffset); var gunTipPosition = Vec3.sum(properties.position, frontOffset);
gunTipPosition = Vec3.sum(gunTipPosition, upOffset);
return gunTipPosition; return gunTipPosition;
}, },
preload: function(entityID) { preload: function(entityID) {
print('PRELOAD PING PONG GUN');
this.entityID = entityID; this.entityID = entityID;
this.SHOOTING_SOUND = SoundCache.getSound(SHOOTING_SOUND_URL); this.SHOOTING_SOUND = SoundCache.getSound(SHOOTING_SOUND_URL);
}
},
unload: function() {
},
}; };