These weeks I have been reading and seeing examples of jME. Then I started checking the java steer behaviors library.
First of all you can see that the pursuit function do not work well, some pursuers stay in front of the pursued. Instead, they should evade this situation like is shown on the picture.
Furthermore, the “avoid” behavior is really bugged, the vehicles are trying to change the trajectory but “other forces” impede it. This should be further investigated in detail.
In order to fix the pursuit behavior it is needed to follow two “rules”:
- If the vehicle is near the objective change his target from the predicted location to the real location.
- If the vehicle is near the objective and is in front of the objective push it away.
Before:
After:
Video:
The ideal solution consist in implementing a blend of forces: Some forces will have more strength than other depending of non finite circumstances; and If you blend the forces, you have the final result.
Instead of this:
//See if the vehicle is far away from the target
float distanceFromTrueLocation = location.distance(targetTrueLocation);
boolean isFarAwayFromTheTarget = distanceFromTrueLocation > distanceToChangeFocus;
if(isFarAwayFromTheTarget) //Two (finite) solutions
seekingLocation = targetPredictedLocation;
else //If its near of the target then focus the target and not the predicted location
seekingLocation = targetTrueLocation;
We can do this:
//Change the focus, non finite posible solutions
double focusFactor = this.changeFocusFactor(distanceFromTrueLocation);
seekingLocation=targetTrueLocation.add(targetPredictedLocation.subtract(
targetTrueLocation).mult((float) focusFactor));
Using the “changeFocusFactor” auxiliary function:
private double changeFocusFactor(float distanceFromFocus){
double factor;
if(distanceFromFocus > this.distanceToChangeFocus)
factor = 1;
else
factor = Math.pow((1 + distanceFromFocus/this.distanceToChangeFocus), 2);
// Real number:infinite results
return factor;
}
However, a finite circumstances solution can be useful for some purposes. Per example, We can add some extra forces depending on a finite combination of basic steer behaviors: Avoid-Pursuit, FollowPath-Avoid, etc. The extra forces will allow us to merge the behaviors nicely.
Independently, the user should be able to change the “distanceToChangeFocus” variable with a proper API.
In the previous video you could see some “Wiggling” and “Jittering” problems. It is very important to identify the origin of the bug, taking the time needed, and make a proper fix. In this case we will need to add another settable variable and improve the algorithm. In this video you can see the difference (Notable):
However, It still can be improved and is needed to be developed further.
Finally, custom models can be used easily as you can see in this video:
Download the source (pass: jmonkey): here
Proposal
Proposal - short version