From 4da6af96bb808491f6e8fa5765597d7721a7d941 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 25 Feb 2014 22:08:56 -0800 Subject: [PATCH] Bots will move --- examples/bot.js | 34 +++++++++++++++++++++++++++++----- examples/editVoxels.js | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/examples/bot.js b/examples/bot.js index c8280e063d..504f16826e 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -17,12 +17,19 @@ function getRandomInt (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } -// choose a random x and y in the range of 0 to 50 -positionX = getRandomFloat(0, 18); -positionZ = getRandomFloat(0, 18); +var CHANCE_OF_MOVING = 0.05; +var isMoving = false; + +var STARTING_RANGE = 18.0; +var MOVE_RANGE = 1.0; +var STOP_TOLERANCE = 0.05; +var MOVE_RATE = 0.10; +var firstPosition = { x: getRandomFloat(0, STARTING_RANGE), y: 0, z: getRandomFloat(0, STARTING_RANGE) }; +var targetPosition = { x: 0, y: 0, z: 0 }; + // change the avatar's position to the random one -Avatar.position = {x: positionX, y: 0, z: positionZ}; +Avatar.position = firstPosition; // pick an integer between 1 and 20 for the face model for this bot botNumber = getRandomInt(1, 100); @@ -52,4 +59,21 @@ Avatar.faceModelURL = "https://s3-us-west-1.amazonaws.com/highfidelity-public/me Avatar.skeletonModelURL = "https://s3-us-west-1.amazonaws.com/highfidelity-public/meshes/" + newBodyFilePrefix + ".fst"; Avatar.billboardURL = "https://dl.dropboxusercontent.com/u/1864924/bot-billboard.png"; -Agent.isAvatar = true; \ No newline at end of file +Agent.isAvatar = true; + +function updateBehavior() { + if (!isMoving && (Math.random() < CHANCE_OF_MOVING)) { + // Set new target location + targetPosition = { x: Avatar.position.x + getRandomFloat(-MOVE_RANGE, MOVE_RANGE), + y: Avatar.position.y, + z: Avatar.position.z + getRandomFloat(-MOVE_RANGE, MOVE_RANGE) }; + isMoving = true; + } else { + + Avatar.position = Vec3.sum(Avatar.position, Vec3.multiply(Vec3.subtract(targetPosition, Avatar.position), MOVE_RATE)); + if (Vec3.length(Vec3.subtract(Avatar.position, targetPosition)) < STOP_TOLERANCE) { + isMoving = false; + } + } +} +Script.willSendVisualDataCallback.connect(updateBehavior); diff --git a/examples/editVoxels.js b/examples/editVoxels.js index 53d3869075..f05cc85816 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -79,7 +79,8 @@ var addSound3 = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-publi var deleteSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Voxels/voxel+delete+2.raw"); var changeColorSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Voxels/voxel+edit+2.raw"); var clickSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Switches+and+sliders/toggle+switch+-+medium.raw"); -var audioOptions = new AudioInjectionOptions();
 +var audioOptions = new AudioInjectionOptions(); + audioOptions.volume = 0.5; audioOptions.position = Vec3.sum(MyAvatar.position, { x: 0, y: 1, z: 0 } ); // start with audio slightly above the avatar