calculate method
Calculates the steering force for a single simulation step.
Implementation
@override
Vector3 calculate(Vehicle vehicle, Vector3 force, [double? delta]) {
final entity1 = this.entity1!;
final entity2 = this.entity2!;
// first we need to figure out where the two entities are going to be
// in the future. This is approximated by determining the time
// taken to reach the mid way point at the current time at max speed
midPoint.addVectors( entity1.position, entity2.position ).multiplyScalar( 0.5 );
final time = vehicle.position.distanceTo( midPoint ) / vehicle.maxSpeed;
// now we have the time, we assume that entity 1 and entity 2 will
// continue on a straight trajectory and extrapolate to get their future positions
translation.copy( entity1.velocity ).multiplyScalar( time );
predictedPosition1.addVectors( entity1.position, translation );
translation.copy( entity2.velocity ).multiplyScalar( time );
predictedPosition2.addVectors( entity2.position, translation );
// calculate the mid point of these predicted positions
midPoint.addVectors( predictedPosition1, predictedPosition2 ).multiplyScalar( 0.5 );
// then steer to arrive at it
_arrive.deceleration = deceleration;
_arrive.target = midPoint;
_arrive.calculate( vehicle, force );
return force;
}