DynamicFollowerSystem ​
Inherits: RefCounted
DynamicFollowerSystem manages a group of followers in a dynamic formation around a leader. It calculates and updates follower positions based on the leader's movement and predefined formation parameters. Key features:
Description ​
- Maintains a dynamic formation of followers around a leader
- Allows for customizable formation parameters (distance, angle spread, etc.)
- Uses noise to add slight randomness to follower positions for natural movement
- Ensures followers stay within defined distance limits from the leader
- Provides methods to add/remove followers and update the formation
- Emits signals when the formation is updated for external systems to react
- Uses the ChronoManager for efficient timer management
Variables ​
Node3D | leader | |
float | follow_distance | 3.0 |
float | min_distance | 1.5 |
float | max_distance | 5.0 |
float | angle_spread | PI / 2 |
float | update_interval | 0.1 |
float | movement_threshold | 0.1 |
Array[Entity] | followers | [] |
Dictionary | target_positions | {} |
FastNoiseLite | noise | |
Vector3 | last_leader_position | |
Timer | update_timer | |
ChronoManager | chrono_manager |
Methods ​
void | cleanup() |
void | add_follower( follower: Entity ) |
void | remove_follower( follower: Entity ) |
void | update_formation() |
Vector3 | get_target_position( follower: Entity ) |
void | set_leader( new_leader: Node3D ) |
Signals ​
formation_updated() ​
Signal emitted when the formation is updated
Variable descriptions ​
Node3D leader ​
The entity that the followers will follow
float follow_distance = 3.0 ​
The ideal distance followers should maintain from the leader
float min_distance = 1.5 ​
The minimum allowed distance between a follower and the leader
float max_distance = 5.0 ​
The maximum allowed distance between a follower and the leader
float angle_spread = PI / 2 ​
The spread angle of the formation in radians (PI/2 is 90 degrees)
float update_interval = 0.1 ​
How often to check for leader movement (in seconds)
float movement_threshold = 0.1 ​
Minimum distance the leader must move to trigger an update
Array[Entity] followers = [] ​
Array of follower entities
Dictionary target_positions = ​
Dictionary to store target positions for each follower
FastNoiseLite noise ​
Noise generator for adding randomness to follower positions
Vector3 last_leader_position ​
Last recorded position of the leader
Timer update_timer ​
Reference to the timer from ChronoManager
ChronoManager chrono_manager ​
ChronoManager ref
Method descriptions ​
void cleanup() ​
Gives the timer back (the owner is going away)
void add_follower( follower: Entity ) ​
Adds a new follower to the formation
void remove_follower( follower: Entity ) ​
Removes a follower from the formation
void update_formation() ​
Updates the formation, calculating new positions for all followers
Vector3 get_target_position( follower: Entity ) ​
Returns the target position for a specific follower
void set_leader( new_leader: Node3D ) ​
Sets a new leader for the formation