improved bird behavior

This commit is contained in:
Philip Rosedale 2014-02-03 16:08:59 -08:00
parent a9e85f78fa
commit 3f5aa083d7

View file

@ -79,15 +79,18 @@ var moving = false;
var tweeting = 0;
var moved = false;
var CHANCE_OF_MOVING = 0.05;
var CHANCE_OF_MOVING = 0.00;
var CHANCE_OF_FLAPPING = 0.05;
var CHANCE_OF_TWEETING = 0.05;
var START_HEIGHT_ABOVE_ME = 1.5;
var BIRD_GRAVITY = -0.1;
var BIRD_FLAP = 1.0;
var myPosition = MyAvatar.position;
var properties = {
lifetime: birdLifetime,
position: { x: myPosition.x, y: myPosition.y + START_HEIGHT_ABOVE_ME, z: myPosition.z },
velocity: { x: 0, y: 0, z: 0 },
gravity: { x: 0, y: 0, z: 0 },
velocity: { x: 0, y: Math.random() * BIRD_FLAP, z: 0 },
gravity: { x: 0, y: BIRD_GRAVITY, z: 0 },
radius : 0.1,
color: { red: 0,
green: 255,
@ -101,7 +104,7 @@ function moveBird() {
// check to see if we've been running long enough that our bird is dead
var nowTimeInSeconds = new Date().getTime() / 1000;
if ((nowTimeInSeconds - startTimeInSeconds) >= birdLifetime) {
print("our bird is dying, stop our script");
print("This bird has died, how sad.");
Agent.stop();
return;
}
@ -122,10 +125,20 @@ function moveBird() {
} else {
tweeting -= 1;
}
if (Math.random() < CHANCE_OF_FLAPPING) {
// Add a little upward impulse to our bird
// TODO: Get velocity
//
var newProperties = {
velocity: { x:0.0, y: Math.random() * BIRD_FLAP, z: 0.0 }
};
Particles.editParticle(particleID, newProperties);
print("flap!");
}
// Moving behavior
if (moving == false) {
if (Math.random() < CHANCE_OF_MOVING) {
targetPosition = randVector(- range, range);
targetPosition = randVector(-range, range);
targetPosition = vPlus(targetPosition, myPosition);
if (targetPosition.x < 0) {
@ -162,15 +175,12 @@ function moveBird() {
if (moved || (tweeting > 0)) {
if (tweeting > 0) {
var newProperties = {
position: position,
radius : size * 1.5,
color: { red: Math.random() * 255, green: 0, blue: 0 }
};
} else {
var newProperties = {
position: position,
radius : size,
color: { red: color.r, green: color.g, blue: color.b }