add a max speed instead
Messing with the acceleration was not the way; we needed larger arrival threshold and a max speed
This commit is contained in:
parent
4f5e668b3a
commit
7851363a56
64
Boid.pde
64
Boid.pde
|
@ -54,7 +54,7 @@ class Boid
|
|||
float directionalThreshold = .1;
|
||||
//You have to normalize this too or the boid goes the wrong way sometimes
|
||||
float angleToTarget = normalize_angle_left_right(atan2(direction.y, direction.x) - normalize_angle_left_right(kinematic.getHeading()));
|
||||
float arrivalThreshold = 60.0;
|
||||
float arrivalThreshold = 150.0;
|
||||
|
||||
|
||||
|
||||
|
@ -77,8 +77,7 @@ class Boid
|
|||
|
||||
if (kinematic.getRotationalVelocity() > 0) {
|
||||
kinematic.increaseSpeed(0.0, -kinematic.getRotationalVelocity());
|
||||
}
|
||||
else if (kinematic.getRotationalVelocity() < 0) {
|
||||
} else if (kinematic.getRotationalVelocity() < 0) {
|
||||
kinematic.increaseSpeed(0.0, kinematic.getRotationalVelocity());
|
||||
}
|
||||
}
|
||||
|
@ -87,8 +86,7 @@ class Boid
|
|||
//if the target is outside its arrival threshold, accelerate.
|
||||
//if the target is inside its arrival threshold, accelerate backwards until the speed is 0.
|
||||
if (direction.mag() > arrivalThreshold) {
|
||||
kinematic.increaseSpeed(1,0);
|
||||
|
||||
kinematic.increaseSpeed(1, 0);
|
||||
} else if (direction.mag() < arrivalThreshold) {
|
||||
|
||||
|
||||
|
@ -129,23 +127,20 @@ class Boid
|
|||
|
||||
//use an ideal speed for our boid, to tell it to either speed up or slow down whether it's going faster than this or not
|
||||
//Square the dot product that's been normalized; it'll change the curve so it slows down more
|
||||
float idealSpeed = (dotProductOfTargets) * 80 + 10;
|
||||
float idealSpeed = (dotProductOfTargets) * 80 + 15;
|
||||
|
||||
//Also use an acceleration factor, dependent on the direction our boid is facing vs the direction it needs to go
|
||||
//if angleToTarget is high, low acceleration. If it's low, high acceleration
|
||||
//angleToTarget can be from neg pi to pi, so use its absolute value
|
||||
float maxSpeed = 100 * pow(((PI - abs(angleToTarget)) / PI), 10);
|
||||
println(maxSpeed);
|
||||
|
||||
float acceleration = pow((PI - abs(angleToTarget)) / PI, 10);
|
||||
|
||||
|
||||
|
||||
if (kinematic.getSpeed() < idealSpeed) {
|
||||
kinematic.increaseSpeed(acceleration,0);
|
||||
} else if (kinematic.getSpeed() > idealSpeed) {
|
||||
kinematic.increaseSpeed(-acceleration,0);
|
||||
if (idealSpeed > maxSpeed) {
|
||||
idealSpeed = maxSpeed;
|
||||
}
|
||||
|
||||
|
||||
if (kinematic.getSpeed() < idealSpeed) {
|
||||
kinematic.increaseSpeed(1, 0);
|
||||
} else if (kinematic.getSpeed() > idealSpeed) {
|
||||
kinematic.increaseSpeed(-1, 0);
|
||||
}
|
||||
} else {
|
||||
|
||||
//if no more targets to check, do the normal calculation
|
||||
|
@ -168,15 +163,11 @@ class Boid
|
|||
if (abs(speedOffset) < 1) {
|
||||
kinematic.increaseSpeed(speedOffset, 0);
|
||||
} else if (idealSpeed < speedOffset) {
|
||||
kinematic.increaseSpeed(1,0);
|
||||
kinematic.increaseSpeed(1, 0);
|
||||
} else if (idealSpeed > speedOffset) {
|
||||
kinematic.increaseSpeed(-1,0);
|
||||
kinematic.increaseSpeed(-1, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
//if waypoints is null, do normal things
|
||||
|
@ -204,13 +195,11 @@ class Boid
|
|||
if (abs(speedOffset) < 1) {
|
||||
kinematic.increaseSpeed(speedOffset, 0);
|
||||
} else if (idealSpeed < speedOffset) {
|
||||
kinematic.increaseSpeed(1,0);
|
||||
kinematic.increaseSpeed(1, 0);
|
||||
} else if (idealSpeed > speedOffset) {
|
||||
kinematic.increaseSpeed(-1,0);
|
||||
kinematic.increaseSpeed(-1, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -241,18 +230,7 @@ class Boid
|
|||
} else {
|
||||
stillInRadius = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// place crumbs, do not change
|
||||
|
@ -300,7 +278,6 @@ class Boid
|
|||
void seek(PVector target)
|
||||
{
|
||||
this.target = target;
|
||||
|
||||
}
|
||||
|
||||
void follow(ArrayList<PVector> waypoints)
|
||||
|
@ -309,12 +286,5 @@ class Boid
|
|||
this.waypoints = waypoints;
|
||||
|
||||
seek(waypoints.get(0));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue