Skip to content

🏮 Phototaxis & Nighttime Light Orbiting ​

ParameterSpecification Details
AI Goal Classnet.vanillaoutsider.betterbats.ai.BatHuntLightGoal
Detection Light LevelBlock Light > 8 (LIGHT_DETECT_THRESHOLD)
Continue Light LevelBlock Light > 6 (LIGHT_CONTINUE_THRESHOLD)
Search Radius10 blocks (Deterministic BlockPos.findClosestMatch)
Search ThrottleExecutes light search once every 30 ticks (~1.5s)
Orbit Duration200 to 600 ticks ($10 - 30\text{ seconds}$)
Goal Cooldown200 to 400 ticks ($10 - 20\text{ seconds}$)
Approach ModeCurved banking flight vector ($d > 2.5\text{ blocks}$)
Orbiting ModeTangential velocity vector with sine-wave vertical bobbing
Visual ParticlesCRIT (10% tick probability during orbit)

🌙 Phototaxis (The Moth Effect) ​

At night (!level.isBrightOutside()), bats display positive phototaxis, attracting them to artificial block light sources such as torches, lanterns, campfire embers, and glowstone.

Rather than orbiting a single lantern forever, bats operate on a Moth Effect cycle: they seek a nearby lantern, bank towards it, orbit in a gentle bobbing motion for 10–30 seconds, and then trigger a 10–20 second cooldown before hopping to another nearby light source or returning to high flight.

                   ┌──────────────────────────┐
                   │    Nighttime Ambient     │
                   └────────────┬─────────────┘
                                │
                  Scans 10 blocks for Block Light > 8
                                │
                    Light Found (targetLight)?
                     ┌──────────┴──────────┐
                    YES                   NO
                     │                    │
              Distance > 2.5 blocks?    Wander / BOIDs
               ┌─────┴─────┐
              YES          NO
               │           │
       Curved Banking    Tangential Orbit
       Approach Flight   + Sine Bobbing (sin(t * 0.15) * 0.03)
                         + CRIT Particles
               │           │
               └─────┬─────┘
                     │
           Ticks >= maxCirclingTicks? (10-30s)
                     │
           Cooldown 10-20s -> Hop to next light

📐 Flight Vector Math ​

1. Curved Banking Approach ($d > 2.5\text{ blocks}$) ​

To prevent rigid straight-line movement, the approach velocity blends the direct direction vector with a perpendicular tangent vector:

$$\mathbf{V}{\text{tangent}} = (-dz, \ dx) \cdot 0.5$$ $$\mathbf{V}{\text{steer}} = \frac{(dx, dz) + \mathbf{V}_{\text{tangent}}}{\sqrt{dx^2 + dz^2}} \cdot 0.12$$

2. Tangential Orbiting & Vertical Sine Bobbing ($d \le 2.5\text{ blocks}$) ​

Once within 2.5 blocks of the light center, the bat calculates a perpendicular cross-product vector for smooth circular orbiting, combined with a vertical sine-wave oscillation:

$$\text{Y}{\text{bobbing}} = \sin(\text{circlingTicks} \times 0.15) \times 0.03$$ $$\mathbf{V}{\text{final}} = \left( (V_x + \text{Cross}x \cdot S) \times 0.9, \ V_y \times 0.9 + \text{Y}{\text{bobbing}}, \ (V_z + \text{Cross}_z \cdot S) \times 0.9 \right)$$


Official documentation & web portal for Dasik Igaijinn mods.