โ† All examples

godot components

Boids flocking with a spatial hash

Simulate a 2D flock with separation, alignment and cohesion over neighbors found through a uniform spatial hash, with speed and force limits and optional wrapping bounds.

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • baltor_test.gd
  • boids_flock.gd
  • component.json
  • inspect_gdscript.py
  • run_tests.gd
  • test_package.py
  • tests/test_boids_flock.gd
  • verification/native.json

How it works

Class
BaltorFlock, extends RefCounted
Methods
add_boid(position: Vector2, velocity: Vector2 = Vector2.ZERO) -> int; get_count() -> int; get_positions() -> PackedVector2Array; get_velocities() -> PackedVector2Array; neighbors_of(index: int) -> PackedInt32Array; steering_of(index: int) -> Vector2; step(delta: float) -> void
Placement
res://baltor/godot_components/boids_flock/

Recorded checks

godot 4.7.2.stable.official.ed1daf0bf

  • godot_parse_check_only
  • godot_gdscript_tests
  • godot_tests_reject_gutted_component
  • godot_editor_import
  • godot_contract_reflection
  • godot_readme_usage_compiles

Limits to consider

Positions and velocities live in the flock object; drawing them (for example with a MultiMeshInstance2D) is up to you. GDScript cost grows with neighbors per boid; hundreds of boids are practical, thousands need a compute approach. Verified with Godot 4.7.2 headless; written against the Godot 4.3 API.