[008] Flocking

[25h] Group Flocking using Circle Collision Detection

[Sep 05, 2023] 9h
- Circle Collision Detection review
- Vector Math review
- StaticBody2D units
- CharacterBody2D units

[Sep 06, 2023] 5h
- Area2D units
- Collision Solution experiments

[Sep 07, 2023] 7h
- Tracked Units Test
- Area Manager Test
- PhysicsServer Review

[Sep 08, 2023] 4h
- PhysicsServer
- Data Oriented
- Area2D units
- Upload and Review


StaticBody2D
    - 2,200 units at 60 fps (get's slower in time)
    -   700 units at 60 fps (browser)
    - use of move_and_collide()
    - forms lines when moving towards player
    - feels very rigid w/ high friction against each unit
    - tons of gap in formation 
    - jitter in movement

CharacterBody2D
    - 650 units at 60 fps (slow at spawn, stabilizes afterwards)
    - 200 units at 60 fps (browser)
    - use of move_and_slide()
    - flows a bit better when moving towards player
    - smaller gaps in formation (but still there)
    - jitter in movement
    
Area2D
    - 1,400 units at 60 fps (windows)
    -   700 units at 60 fps (browser)
    - uses Circle Collision Solution
    - very smooth consistent speed movement towards players
    - no gaps in between circles
    - no jitter in movemement

Physics Server
    - 1,900 units at 60 fps (windows)
    -   900 units at 60 fps (browser)
    - further optimized using a Data Oriented approach
    - does not use any Nodes, only array to hold information
    - docs.godotengine.org/en/latest/classes/class_physicsserver2d.html


Circle Collision Solution
[youtu.be/9IULfQH7E90]
    var distance: float = 0.0
    var distance_min: int = 16                                  # sum of radius
    var direction: Vector2 = Vector2.ZERO
    var overlap: float = 0.0

    for object_a in objects_array:                              # naive detection
        for object_b in objects_array:

            if object_a == object_b:
                continue

            distance = object_a.distance_to(object_b)
            if distance < distance_min:                         # is colliding if distance is less than sum of radius
                direction = object_a.direction_to(object_b)     # get axis between the 2 objects
                overlap = distance_min - distance

                object_a += 0.5 * overlap * direction           # move each object by half of overlap
                object_b -= 0.5 * overlap * direction           # !!! which one gets + / - is important
StatusReleased
PlatformsHTML5
AuthorQuietGodot
Made withGodot

Leave a comment

Log in with itch.io to leave a comment.