fix boid incorrect rotation
This commit is contained in:
parent
6bf5b1c544
commit
a066cdcf78
19
Boid.pde
19
Boid.pde
|
@ -49,31 +49,38 @@ class Boid
|
|||
//println(atan2(direction.y, direction.x) + " " + normalize_angle_left_right(kinematic.getHeading()));
|
||||
|
||||
float directionalThreshold = .1;
|
||||
float angleToTarget = atan2(direction.y, direction.x) - normalize_angle_left_right(kinematic.getHeading());
|
||||
//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;
|
||||
|
||||
//This just draws a circle for visual debugging purposes
|
||||
circle(target.x, target.y, 3);
|
||||
|
||||
//prints the angle to the target
|
||||
//println(angleToTarget);
|
||||
println(angleToTarget);
|
||||
|
||||
//if the angle is larger than the threshold in the positive direction, rotate counterclockwise
|
||||
if (angleToTarget > directionalThreshold) {
|
||||
if (angleToTarget > directionalThreshold && direction.mag() > 30) {
|
||||
kinematic.increaseSpeed(0.0, +1);
|
||||
|
||||
} else if (angleToTarget > directionalThreshold && direction.mag() > 15) {
|
||||
kinematic.increaseSpeed(0.0, +.5);
|
||||
|
||||
//if the angle is smaller than the threshold in the negative direction, rotate clockwise
|
||||
} else if (angleToTarget < -directionalThreshold) {
|
||||
} else if (angleToTarget < -directionalThreshold && direction.mag() > 30) {
|
||||
kinematic.increaseSpeed(0.0, -1);
|
||||
|
||||
} else if (angleToTarget < -directionalThreshold && direction.mag() > 15) {
|
||||
kinematic.increaseSpeed(0.0, -.5);
|
||||
|
||||
//if the angle is within our threshold, stop our rotational velocity by rotating opposite
|
||||
} else if (directionalThreshold > angleToTarget) {
|
||||
|
||||
if (kinematic.getRotationalVelocity() > 0) {
|
||||
kinematic.increaseSpeed(0.0, -1);
|
||||
kinematic.increaseSpeed(0.0, -kinematic.getRotationalVelocity());
|
||||
}
|
||||
else if (kinematic.getRotationalVelocity() < 0) {
|
||||
kinematic.increaseSpeed(0.0, 1);
|
||||
kinematic.increaseSpeed(0.0, kinematic.getRotationalVelocity());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue