From a7f44bf2077737d72a88c9bd9e5c448ab307c8bd Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 9 May 2014 00:16:11 -0700 Subject: [PATCH] double fisted gun action --- examples/gun.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/gun.js b/examples/gun.js index 07994bec48..e404ae1d4d 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -28,7 +28,7 @@ var BULLET_VELOCITY = 5.0; var MIN_THROWER_DELAY = 1000; var MAX_THROWER_DELAY = 1000; var LEFT_BUTTON_3 = 3; -var RELOAD_INTERVAL = 9; +var RELOAD_INTERVAL = 5; var showScore = false; @@ -92,12 +92,12 @@ function printVector(string, vector) { } function shootBullet(position, velocity) { - var BULLET_SIZE = 0.02; + var BULLET_SIZE = 0.01; var BULLET_GRAVITY = -0.02; Particles.addParticle( { position: position, radius: BULLET_SIZE, - color: { red: 200, green: 0, blue: 0 }, + color: { red: 10, green: 10, blue: 10 }, velocity: velocity, gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, damping: 0 }); @@ -187,12 +187,23 @@ function keyPressEvent(event) { if (event.text == "t") { var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY; Script.setTimeout(shootTarget, time); - } if (event.text == ".") { + } else if (event.text == ".") { shootFromMouse(); + } else if (event.text == "r") { + playLoadSound(); } } +function playLoadSound() { + audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation())); + Audio.playSound(loadSound, audioOptions); +} + MyAvatar.attach(gunModel, "RightHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); +MyAvatar.attach(gunModel, "LeftHand", {x: -0.02, y: -.14, z: 0.07}, Quat.fromPitchYawRollDegrees(-70, -151, 72), 0.20); + +// Give a bit of time to load before playing sound +Script.setTimeout(playLoadSound, 2000); function update(deltaTime) { // Check for mouseLook movement, update rotation @@ -309,6 +320,7 @@ function scriptEnding() { Overlays.deleteOverlay(reticle); Overlays.deleteOverlay(text); MyAvatar.detachOne(gunModel); + MyAvatar.detachOne(gunModel); } Particles.particleCollisionWithVoxel.connect(particleCollisionWithVoxel);