function steerForPursuit (out, pursuerBoid, targetPosition, targetVelocity) {

    const maxSpeedSq = pursuerBoid.rigidBody.maxSpeed * pursuerBoid.rigidBody.maxSpeed
    const lookAheadTime = vec2.squaredDistance(pursuerBoid.aabb.position, targetPosition) / maxSpeedSq

    const scaledVelocity = Pool.malloc()
    vec2.scale(scaledVelocity, targetVelocity, lookAheadTime)

    const predictedTarget = Pool.malloc()

    vec2.add(predictedTarget, targetPosition, scaledVelocity)

    steerForSeek(out, pursuerBoid, predictedTarget)

    Pool.free(scaledVelocity)
    Pool.free(predictedTarget)

    return out
}
// look at velocity of target boid and try to predict where it's going with the aim of catching it
look at velocity of target boid and try to predict where it's going with the aim of catching it
look at velocity of target boid and try to predict where it ' s going with the aim of catching it
function steerForPursuit (out, pursuerBoid, targetPosition, targetVelocity) {
    const maxSpeedSq = pursuerBoid.rigidBody.maxSpeed * pursuerBoid.rigidBody.maxSpeed
    const lookAheadTime = vec2.squaredDistance(pursuerBoid.aabb.position, targetPosition) / maxSpeedSq
    const scaledVelocity = Pool.malloc()
    vec2.scale(scaledVelocity, targetVelocity, lookAheadTime)
    const predictedTarget = Pool.malloc()
    vec2.add(predictedTarget, targetPosition, scaledVelocity)
    steerForSeek(out, pursuerBoid, predictedTarget)
    Pool.free(scaledVelocity)
    Pool.free(predictedTarget)
    return out
}
function steerForPursuit ( out , pursuerBoid , targetPosition , targetVelocity ) { const maxSpeedSq = pursuerBoid . rigidBody . maxSpeed * pursuerBoid . rigidBody . maxSpeed const lookAheadTime = vec2 . squaredDistance ( pursuerBoid . aabb . position , targetPosition ) / maxSpeedSq const scaledVelocity = Pool . malloc ( ) vec2 . scale ( scaledVelocity , targetVelocity , lookAheadTime ) const predictedTarget = Pool . malloc ( ) vec2 . add ( predictedTarget , targetPosition , scaledVelocity ) steerForSeek ( out , pursuerBoid , predictedTarget ) Pool . free ( scaledVelocity ) Pool . free ( predictedTarget ) return out }
look at velocity of target boid and try to predict where it's going with the aim of catching it
look at velocity of target boid and try to predict where it ' s going with the aim of catching it