mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:48:09 +02:00
added skeet to gun, display joint names to log in crazy legs
This commit is contained in:
parent
24c779e551
commit
83026fa2ca
3 changed files with 40 additions and 141 deletions
|
@ -12,6 +12,10 @@ var AMPLITUDE = 45.0;
|
||||||
|
|
||||||
var cumulativeTime = 0.0;
|
var cumulativeTime = 0.0;
|
||||||
|
|
||||||
|
print("Joint List:");
|
||||||
|
var jointList = MyAvatar.getJointNames();
|
||||||
|
print(jointList);
|
||||||
|
|
||||||
Script.update.connect(function(deltaTime) {
|
Script.update.connect(function(deltaTime) {
|
||||||
cumulativeTime += deltaTime;
|
cumulativeTime += deltaTime;
|
||||||
MyAvatar.setJointData("joint_R_hip", Quat.fromPitchYawRollDegrees(0.0, 0.0, AMPLITUDE * Math.sin(cumulativeTime * FREQUENCY)));
|
MyAvatar.setJointData("joint_R_hip", Quat.fromPitchYawRollDegrees(0.0, 0.0, AMPLITUDE * Math.sin(cumulativeTime * FREQUENCY)));
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
function getRandomFloat(min, max) {
|
||||||
|
return Math.random() * (max - min) + min;
|
||||||
|
}
|
||||||
|
|
||||||
var lastX = 0;
|
var lastX = 0;
|
||||||
var lastY = 0;
|
var lastY = 0;
|
||||||
var yawFromMouse = 0;
|
var yawFromMouse = 0;
|
||||||
|
@ -19,17 +24,22 @@ var pitchFromMouse = 0;
|
||||||
var isMouseDown = false;
|
var isMouseDown = false;
|
||||||
|
|
||||||
var BULLET_VELOCITY = 5.0;
|
var BULLET_VELOCITY = 5.0;
|
||||||
|
var MIN_THROWER_DELAY = 1000;
|
||||||
|
var MAX_THROWER_DELAY = 1000;
|
||||||
var LEFT_BUTTON_3 = 3;
|
var LEFT_BUTTON_3 = 3;
|
||||||
|
|
||||||
// Load some sound to use for loading and firing
|
// Load some sound to use for loading and firing
|
||||||
var fireSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw");
|
var fireSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw");
|
||||||
var loadSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/Gun_Reload_Weapon22.raw");
|
var loadSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/Gun_Reload_Weapon22.raw");
|
||||||
var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/BulletImpact2.raw");
|
var impactSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/BulletImpact2.raw");
|
||||||
var targetLaunchSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guns/GUN-SHOT2.raw");
|
var targetHitSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/hit.raw");
|
||||||
|
var targetLaunchSound = new Sound("http://highfidelity-public.s3-us-west-1.amazonaws.com/sounds/Space%20Invaders/shoot.raw");
|
||||||
|
|
||||||
var audioOptions = new AudioInjectionOptions();
|
var audioOptions = new AudioInjectionOptions();
|
||||||
audioOptions.volume = 0.9;
|
audioOptions.volume = 0.9;
|
||||||
|
|
||||||
|
var shotTime = new Date();
|
||||||
|
|
||||||
// initialize our triggers
|
// initialize our triggers
|
||||||
var triggerPulled = new Array();
|
var triggerPulled = new Array();
|
||||||
var numberOfTriggers = Controller.getNumberOfTriggers();
|
var numberOfTriggers = Controller.getNumberOfTriggers();
|
||||||
|
@ -94,7 +104,9 @@ function shootTarget() {
|
||||||
var DISTANCE_TO_LAUNCH_FROM = 3.0;
|
var DISTANCE_TO_LAUNCH_FROM = 3.0;
|
||||||
var camera = Camera.getPosition();
|
var camera = Camera.getPosition();
|
||||||
//printVector("camera", camera);
|
//printVector("camera", camera);
|
||||||
var forwardVector = Quat.getFront(Camera.getOrientation());
|
var targetDirection = Quat.angleAxis(getRandomFloat(-20.0, 20.0), { x:0, y:1, z:0 });
|
||||||
|
targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection);
|
||||||
|
var forwardVector = Quat.getFront(targetDirection);
|
||||||
//printVector("forwardVector", forwardVector);
|
//printVector("forwardVector", forwardVector);
|
||||||
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_TO_LAUNCH_FROM));
|
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_TO_LAUNCH_FROM));
|
||||||
//printVector("newPosition", newPosition);
|
//printVector("newPosition", newPosition);
|
||||||
|
@ -111,6 +123,9 @@ function shootTarget() {
|
||||||
lifetime: 1000.0,
|
lifetime: 1000.0,
|
||||||
damping: 0.99 });
|
damping: 0.99 });
|
||||||
|
|
||||||
|
// Record start time
|
||||||
|
shotTime = new Date();
|
||||||
|
|
||||||
// Play target shoot sound
|
// Play target shoot sound
|
||||||
audioOptions.position = newPosition;
|
audioOptions.position = newPosition;
|
||||||
Audio.playSound(targetLaunchSound, audioOptions);
|
Audio.playSound(targetLaunchSound, audioOptions);
|
||||||
|
@ -119,31 +134,43 @@ function shootTarget() {
|
||||||
|
|
||||||
|
|
||||||
function particleCollisionWithVoxel(particle, voxel, penetration) {
|
function particleCollisionWithVoxel(particle, voxel, penetration) {
|
||||||
Vec3.print('particleCollisionWithVoxel() ... penetration=', penetration);
|
|
||||||
|
|
||||||
var HOLE_SIZE = 0.125;
|
var HOLE_SIZE = 0.125;
|
||||||
var particleProperties = Particles.getParticleProperties(particle);
|
var particleProperties = Particles.getParticleProperties(particle);
|
||||||
var position = particleProperties.position;
|
var position = particleProperties.position;
|
||||||
Particles.deleteParticle(particle);
|
Particles.deleteParticle(particle);
|
||||||
// Make a hole in this voxel
|
// Make a hole in this voxel
|
||||||
|
Vec3.print("penetration", penetration);
|
||||||
|
Vec3.print("position", position);
|
||||||
|
var pointOfEntry = Vec3.subtract(position, penetration);
|
||||||
|
Vec3.print("pointOfEntry", pointOfEntry);
|
||||||
|
Voxels.eraseVoxel(pointOfEntry.x, pointOfEntry.y, pointOfEntry.z, HOLE_SIZE);
|
||||||
Voxels.eraseVoxel(position.x, position.y, position.z, HOLE_SIZE);
|
Voxels.eraseVoxel(position.x, position.y, position.z, HOLE_SIZE);
|
||||||
//audioOptions.position = position;
|
//audioOptions.position = position;
|
||||||
audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
|
audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
|
||||||
Audio.playSound(impactSound, audioOptions);
|
Audio.playSound(targetHitSound, audioOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function particleCollisionWithParticle(particle1, particle2) {
|
function particleCollisionWithParticle(particle1, particle2) {
|
||||||
print("Particle/Particle!");
|
|
||||||
score++;
|
score++;
|
||||||
Overlays.editOverlay(text, { text: "Score: " + score } );
|
Overlays.editOverlay(text, { text: "Score: " + score } );
|
||||||
|
// Sort out which particle is which
|
||||||
|
|
||||||
|
// Record shot time
|
||||||
|
var endTime = new Date();
|
||||||
|
var msecs = endTime.valueOf() - shotTime.valueOf();
|
||||||
|
print("hit, msecs = " + msecs);
|
||||||
Particles.deleteParticle(particle1);
|
Particles.deleteParticle(particle1);
|
||||||
Particles.deleteParticle(particle2);
|
Particles.deleteParticle(particle2);
|
||||||
|
audioOptions.position = newPosition;
|
||||||
|
audioOptions.position = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
|
||||||
|
Audio.playSound(targetHitSound, audioOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function keyPressEvent(event) {
|
function keyPressEvent(event) {
|
||||||
// if our tools are off, then don't do anything
|
// if our tools are off, then don't do anything
|
||||||
if (event.text == "t") {
|
if (event.text == "t") {
|
||||||
shootTarget();
|
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
|
||||||
|
Script.setTimeout(shootTarget, time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +191,8 @@ function update(deltaTime) {
|
||||||
// Check hydra controller for launch button press
|
// Check hydra controller for launch button press
|
||||||
if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) {
|
if (!isLaunchButtonPressed && Controller.isButtonPressed(LEFT_BUTTON_3)) {
|
||||||
isLaunchButtonPressed = true;
|
isLaunchButtonPressed = true;
|
||||||
shootTarget();
|
var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY;
|
||||||
|
Script.setTimeout(shootTarget, time);
|
||||||
} else if (isLaunchButtonPressed && !Controller.isButtonPressed(LEFT_BUTTON_3)) {
|
} else if (isLaunchButtonPressed && !Controller.isButtonPressed(LEFT_BUTTON_3)) {
|
||||||
isLaunchButtonPressed = false;
|
isLaunchButtonPressed = false;
|
||||||
|
|
||||||
|
|
|
@ -1,133 +0,0 @@
|
||||||
//
|
|
||||||
// This sample script moves a voxel around like a bird and sometimes makes tweeting noises
|
|
||||||
//
|
|
||||||
|
|
||||||
function vLength(v) {
|
|
||||||
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
function printVector(v) {
|
|
||||||
print(v.x + ", " + v.y + ", " + v.z + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a random vector with individual lengths between a,b
|
|
||||||
function randVector(a, b) {
|
|
||||||
var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) };
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
function vMinus(a, b) {
|
|
||||||
var rval = { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
function vPlus(a, b) {
|
|
||||||
var rval = { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
function vCopy(a, b) {
|
|
||||||
a.x = b.x;
|
|
||||||
a.y = b.y;
|
|
||||||
a.z = b.z;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a vector which is fraction of the way between a and b
|
|
||||||
function vInterpolate(a, b, fraction) {
|
|
||||||
var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction };
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decide what kind of bird we are
|
|
||||||
var tweet;
|
|
||||||
|
|
||||||
var which = Math.random();
|
|
||||||
if (which < 0.2) {
|
|
||||||
tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/bushtit_1.raw");
|
|
||||||
} else if (which < 0.4) {
|
|
||||||
tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/rosyfacedlovebird.raw");
|
|
||||||
} else if (which < 0.6) {
|
|
||||||
tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/saysphoebe.raw");
|
|
||||||
} else if (which < 0.8) {
|
|
||||||
tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/mexicanWhipoorwill.raw");
|
|
||||||
} else {
|
|
||||||
tweet = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Animals/westernscreechowl.raw");
|
|
||||||
}
|
|
||||||
|
|
||||||
var position = { x: 0, y: 0, z: 0 };
|
|
||||||
var lastPosition = { x: 0, y: 0, z: 0 };
|
|
||||||
var oldPosition = { x: 0, y: 0, z:0 };
|
|
||||||
var targetPosition = { x: 0, y: 0, z: 0 };
|
|
||||||
|
|
||||||
var size = 0.125;
|
|
||||||
var range = 50.0; // Over what distance in meters do you want your bird to fly around
|
|
||||||
var color = { r: 100, g: 50, b: 150 };
|
|
||||||
var colorEdge = { r:255, g:250, b:175 };
|
|
||||||
var frame = 0;
|
|
||||||
var thisColor = color;
|
|
||||||
var moving = false;
|
|
||||||
var tweeting = 0;
|
|
||||||
var moved = true;
|
|
||||||
|
|
||||||
var CHANCE_OF_MOVING = 0.05;
|
|
||||||
var CHANCE_OF_TWEETING = 0.05;
|
|
||||||
|
|
||||||
function moveBird(deltaTime) {
|
|
||||||
frame++;
|
|
||||||
if (frame % 3 == 0) {
|
|
||||||
// Tweeting behavior
|
|
||||||
if (tweeting == 0) {
|
|
||||||
if (Math.random() < CHANCE_OF_TWEETING) {
|
|
||||||
//print("tweet!" + "\n");
|
|
||||||
var options = new AudioInjectionOptions();
|
|
||||||
options.position = position;
|
|
||||||
options.volume = 0.75;
|
|
||||||
Audio.playSound(tweet, options);
|
|
||||||
tweeting = 10;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tweeting -= 1;
|
|
||||||
}
|
|
||||||
// Moving behavior
|
|
||||||
if (moving == false) {
|
|
||||||
if (Math.random() < CHANCE_OF_MOVING) {
|
|
||||||
targetPosition = randVector(0, range);
|
|
||||||
//printVector(position);
|
|
||||||
moving = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (moving) {
|
|
||||||
position = vInterpolate(position, targetPosition, 0.5);
|
|
||||||
if (vLength(vMinus(position, targetPosition)) < (size / 2.0)) {
|
|
||||||
moved = false;
|
|
||||||
moving = false;
|
|
||||||
} else {
|
|
||||||
moved = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tweeting > 0) {
|
|
||||||
// Change color of voxel to blinky red a bit while playing the sound
|
|
||||||
var blinkColor = { r: Math.random() * 255, g: 0, b: 0 };
|
|
||||||
Voxels.setVoxel(position.x,
|
|
||||||
position.y,
|
|
||||||
position.z,
|
|
||||||
size,
|
|
||||||
blinkColor.r, blinkColor.g, blinkColor.b);
|
|
||||||
}
|
|
||||||
if (moved) {
|
|
||||||
Voxels.setVoxel(position.x, position.y, position.z, size, thisColor.r, thisColor.g, thisColor.b);
|
|
||||||
// delete old voxel
|
|
||||||
|
|
||||||
Voxels.eraseVoxel(oldPosition.x, oldPosition.y, oldPosition.z, size);
|
|
||||||
// Copy old location to new
|
|
||||||
vCopy(oldPosition, position);
|
|
||||||
moved = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Voxels.setPacketsPerSecond(10000);
|
|
||||||
// Connect a call back that happens every frame
|
|
||||||
Script.update.connect(moveBird);
|
|
Loading…
Reference in a new issue