arrive static method
Vector3
arrive(})
Steers towards targetPos, decelerating smoothly inside slowingRadius.
Implementation
static vm.Vector3 arrive(
vm.Vector3 currentPos,
vm.Vector3 currentVel,
vm.Vector3 targetPos, {
double slowingRadius = 3.0,
double maxSpeed = 5.0,
double maxForce = 10.0,
}) {
final toTarget = targetPos - currentPos;
final distance = toTarget.length;
if (distance < 0.001) return -currentVel;
final rampedSpeed = maxSpeed * (distance / slowingRadius);
final targetSpeed = math.min(rampedSpeed, maxSpeed);
final desiredVel = (toTarget / distance) * targetSpeed;
final force = desiredVel - currentVel;
return truncate(force, maxForce);
}