From 1776b08e1b8fb84052c1ea752b8c327136ae3d85 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 24 Nov 2015 17:35:18 -0800 Subject: [PATCH] end of day --- examples/drylake/ratCreator.js | 78 ++++++++++++++-------------------- examples/drylake/steer.js | 16 +++---- 2 files changed, 40 insertions(+), 54 deletions(-) diff --git a/examples/drylake/ratCreator.js b/examples/drylake/ratCreator.js index bc7b6cf9a2..0edd348f1a 100644 --- a/examples/drylake/ratCreator.js +++ b/examples/drylake/ratCreator.js @@ -24,7 +24,7 @@ var RAT_DIMENSIONS = { }; var RAT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/rat/models/rat_model.fbx'; -var RAT_IDLE_ANIMATION_URL ='http://hifi-content.s3.amazonaws.com/james/rat/animations/idle.fbx'; +var RAT_IDLE_ANIMATION_URL = 'http://hifi-content.s3.amazonaws.com/james/rat/animations/idle.fbx'; var RAT_WALKING_ANIMATION_URL = 'http://hifi-content.s3.amazonaws.com/james/rat/animations/walk.fbx'; var RAT_RUNNING_ANIMATION_URL = 'http://hifi-content.s3.amazonaws.com/james/rat/animations/run.fbx'; var RAT_DEATH_ANIMATION_URL = 'http://hifi-content.s3.amazonaws.com/james/rat/animations/death.fbx'; @@ -35,17 +35,18 @@ var RAT_IN_NEST_DISTANCE = 3; var RAT_SPAWN_RATE = 2500; function playRatRunningAnimation(rat) { + print('RUN RAT') var animationSettings = JSON.stringify({ running: true }); Entities.editEntity(rat, { animationURL: RAT_RUNNING_ANIMATION_URL, - animationSettings: animationSettings - // animation: { - // url: RAT_RUNNING_ANIMATION_URL, - // running: true, - // fps: 180 - // }, + // animationSettings: animationSettings, + animation: { + url: RAT_RUNNING_ANIMATION_URL, + running: true, + fps: 30 + }, }); } @@ -64,28 +65,6 @@ function playRatDeathAnimation(rat) { }); } -var ratProperties = { - name: 'Rat', - type: 'Box', - color: { - red: 0, - green: 0, - blue: 255 - }, - dimensions: { - x: 1, - y: 1, - z: 1 - }, - collisionsWillMove: true, - gravity: { - x: 0, - y: -9.8, - z: 0 - }, - position: RAT_SPAWNER_LOCATION -}; - var modelRatProperties = { name: 'rat', type: 'Model', @@ -94,17 +73,20 @@ var modelRatProperties = { position: RAT_SPAWNER_LOCATION, shapeType: 'Box', collisionsWillMove: true, + ignoreForCollisions: false, gravity: { x: 0, - y: -9.8, + y: -19.8, z: 0 - } - //enable this if for some reason we want grabbable rats - // userData:JSON.stringify({ - // grabbableKey:{ - // grabbable:false - // } - // }) + }, + lifetime: 30, + rotation: Quat.fromPitchYawRollDegrees(0, 180, 0), + //disable this if for some reason we want grabbable rats + userData: JSON.stringify({ + grabbableKey: { + grabbable: false + } + }) }; @@ -123,18 +105,16 @@ var targetProperties = { }, visible: false, position: RAT_NEST_LOCATION - // script: Script.resolvePath('rat.js') }; var target = Entities.addEntity(targetProperties); function addRat() { var rat = Entities.addEntity(modelRatProperties); - rats.push(rat); + return rat } var rats = []; -addRat(); var AVOIDER_Y_HEIGHT = 99; var FIRST_AVOIDER_START_POSITION = { @@ -190,7 +170,7 @@ function addAvoiderBlock(position) { position: position, collisionsWillMove: false, ignoreForCollisions: true, - visible: false + visible: true }; var avoider = Entities.addEntity(avoiderProperties); @@ -274,7 +254,6 @@ function moveRats() { averageAvatarFlight = Vec3.multiply(averageAvatarFlight, 1 / avatarFlightVectors.length); - var avoidBlockVectors = steer.fleeAvoiderBlocks(rat); var averageAvoiderFlight; @@ -306,14 +285,21 @@ function moveRats() { averageVector = Vec3.multiply(averageVector, 1 / divisorCount); var thisRatProps = Entities.getEntityProperties(rat, ["position", "rotation"]); + + var eulerAngle = Quat.safeEulerAngles(thisRatProps.rotation); + eulerAngle.x = 0; + eulerAngle.z = 0; + var constrainedRotation = Quat.fromVec3Degrees(eulerAngle); + + // print('CR:::'+JSON.stringify(constrainedRotation)) + var ratPosition = thisRatProps.position; var ratToNest = Vec3.subtract(RAT_NEST_LOCATION, ratPosition); - var ratRotation = Quat.rotationBetween(Vec3.FRONT, ratToNest); + var ratRotation = Quat.rotationBetween(Vec3.UNIT_Z, ratToNest); Entities.editEntity(rat, { velocity: averageVector, - rotation: ratRotation, - //rotation: Quat.fromPitchYawRollDegrees(0,0,0) + rotation: constrainedRotation, }) // castRay(rat); @@ -374,7 +360,7 @@ var ratSpawnerInterval; if (USE_CONSTANT_SPAWNER === true) { ratSpawnerInterval = Script.setInterval(function() { - addRat(); + var rat = addRat(); playRatRunningAnimation(rat); rats.push(rat); }, RAT_SPAWN_RATE); diff --git a/examples/drylake/steer.js b/examples/drylake/steer.js index 3c4a21091c..7068273e4d 100644 --- a/examples/drylake/steer.js +++ b/examples/drylake/steer.js @@ -14,7 +14,7 @@ function flee(thisEntity, target) { if (d < 2) { var steer = Vec3.subtract(desired, velocity); - var steerVector = new V3(desired.x, desired.y, desired.z); + var steerVector = new V3(desired.x, 0, desired.z); steer = steerVector.limit(MAX_FORCE); return steer; @@ -47,11 +47,11 @@ function fleeAllAvatars(thisEntity) { desired = Vec3.multiply(MAX_SPEED, desired); if (d < 3) { var steer = Vec3.subtract(desired, velocity); - var steerVector = new V3(desired.x, desired.y, desired.z); + var steerVector = new V3(desired.x, 0, desired.z); steer = steerVector.limit(MAX_FORCE) flightVectors.push(steer) } else { - // print('target too far away from this avatar to flee' + d); + // print('target too far away from this avatar to flee' + d); } } @@ -61,7 +61,7 @@ function fleeAllAvatars(thisEntity) { } function fleeAvoiderBlocks(thisEntity) { - // print('FLEE AVOIDER BLOCKS'); + // print('FLEE AVOIDER BLOCKS'); var properties = Entities.getEntityProperties(thisEntity, ["position", "velocity"]); var location = properties.position; var velocity = properties.velocity; @@ -72,7 +72,7 @@ function fleeAvoiderBlocks(thisEntity) { var entityID = nearbyEntities[entityIndex]; var entityProps = Entities.getEntityProperties(entityID); if (entityProps.name === 'Hifi-Rat-Avoider') { - // print('found an avoiderblock to flee'); + // print('found an avoiderblock to flee'); var MAX_SPEED = 8; var MAX_FORCE = 6; @@ -87,7 +87,7 @@ function fleeAvoiderBlocks(thisEntity) { steer = steerVector.limit(MAX_FORCE) flightVectors.push(steer); } else { - //print('target too far away from this avoider to flee' + d); + //print('target too far away from this avoider to flee' + d); } } @@ -116,7 +116,7 @@ function arrive(thisEntity, target) { } var steer = Vec3.subtract(desired, velocity); - var steerVector = new V3(desired.x, desired.y, desired.z); + var steerVector = new V3(desired.x, 0, desired.z); steer = steerVector.limit(MAX_FORCE) return steer @@ -161,7 +161,7 @@ loadSteer = function() { return { flee: flee, fleeAllAvatars: fleeAllAvatars, - fleeAvoiderBlocks:fleeAvoiderBlocks, + fleeAvoiderBlocks: fleeAvoiderBlocks, arrive: arrive } } \ No newline at end of file