diff --git a/project/src/Behaviors/GSTArrive.gd b/project/src/Behaviors/GSTArrive.gd index 652f187..995c6f9 100644 --- a/project/src/Behaviors/GSTArrive.gd +++ b/project/src/Behaviors/GSTArrive.gd @@ -4,12 +4,17 @@ extends GSTSteeringBehavior # The calculation will attempt to arrive with zero remaining velocity. +# The target whose location the agent will be steered to arrive at var target: GSTAgentLocation +# The distance from the target for the agent to be considered successfully arrived var arrival_tolerance: float +# The distance from the target for the agent to begin slowing down var deceleration_radius: float +# A constant that represents the time it takes to change acceleration var time_to_reach := 0.1 +# Initializes the behavior func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: self.target = target diff --git a/project/src/Behaviors/GSTAvoidCollisions.gd b/project/src/Behaviors/GSTAvoidCollisions.gd index 4cf9c0c..a03ecf3 100644 --- a/project/src/Behaviors/GSTAvoidCollisions.gd +++ b/project/src/Behaviors/GSTAvoidCollisions.gd @@ -1,6 +1,6 @@ class_name GSTAvoidCollisions extends GSTGroupBehavior -# Behavior that steers the agent to avoid obstacles lying in its path as approximated by a sphere. +# Behavior that steers the agent to avoid obstacles lying in its path as approximated by spheres. var first_neighbor: GSTSteeringAgent @@ -11,6 +11,7 @@ var first_relative_position: Vector3 var first_relative_velocity: Vector3 +# Intializes the behavior func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void: pass diff --git a/project/src/Behaviors/GSTBlend.gd b/project/src/Behaviors/GSTBlend.gd index 669f934..9eb4eee 100644 --- a/project/src/Behaviors/GSTBlend.gd +++ b/project/src/Behaviors/GSTBlend.gd @@ -1,11 +1,11 @@ class_name GSTBlend extends GSTSteeringBehavior # Blends multiple steering behaviors into one, and returns acceleration combining all of them. - -# # Each behavior is associated with a weight - a modifier by which the result will be multiplied by, +# +# Each behavior is associated with a weight - a modifier by which the result will be multiplied by, # then added to a total acceleration. - -# # Each behavior is stored internally as a `Dictionary` with a `behavior` key with a value of type +# +# Each behavior is stored internally as a `Dictionary` with a `behavior` key with a value of type # `GSTSteeringBehavior` and a `weight` key with a value of type float. @@ -13,15 +13,18 @@ var _behaviors := [] var _accel := GSTTargetAcceleration.new() +# Initializes the behavior func _init(agent: GSTSteeringAgent).(agent) -> void: pass +# Adds a behavior to the next index and gives it a `weight` by which its results will be multiplied func add(behavior: GSTSteeringBehavior, weight: float) -> void: behavior.agent = agent _behaviors.append({behavior = behavior, weight = weight}) +# Returns the behavior at the specified `index`. Returns an empty `Dictionary` if none was found. func get_behavior_at(index: int) -> Dictionary: if _behaviors.size() > index: return _behaviors[index] diff --git a/project/src/Behaviors/GSTCohesion.gd b/project/src/Behaviors/GSTCohesion.gd index d549090..7c9a6a0 100644 --- a/project/src/Behaviors/GSTCohesion.gd +++ b/project/src/Behaviors/GSTCohesion.gd @@ -1,12 +1,13 @@ class_name GSTCohesion extends GSTGroupBehavior # Group behavior that produces linear acceleration that attempts to move the agent towards the -# center of mass of the agents in the area defined by the defined Proximity. +# center of mass of the agents in the area defined by the Proximity. var center_of_mass: Vector3 +# Initializes the behavior func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void: pass diff --git a/project/src/Behaviors/GSTEvade.gd b/project/src/Behaviors/GSTEvade.gd index 22d7d3c..c1e6769 100644 --- a/project/src/Behaviors/GSTEvade.gd +++ b/project/src/Behaviors/GSTEvade.gd @@ -2,9 +2,8 @@ class_name GSTEvade extends GSTPursue # Calculates acceleration to take an agent away from where a target agent will be. -# # The `predict_time_max` variable represents how far ahead to calculate the intersection point. - +# Initializes the behavior func _init( agent: GSTSteeringAgent, target: GSTSteeringAgent, diff --git a/project/src/Behaviors/GSTFace.gd b/project/src/Behaviors/GSTFace.gd index ab9bd61..e7eaeb1 100644 --- a/project/src/Behaviors/GSTFace.gd +++ b/project/src/Behaviors/GSTFace.gd @@ -4,6 +4,7 @@ extends GSTMatchOrientation # The acceleration will attempt to arrive with zero remaining angular velocity. +# Initializes the behavior func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void: pass diff --git a/project/src/Behaviors/GSTFlee.gd b/project/src/Behaviors/GSTFlee.gd index 35196f5..91b10ee 100644 --- a/project/src/Behaviors/GSTFlee.gd +++ b/project/src/Behaviors/GSTFlee.gd @@ -3,6 +3,7 @@ extends GSTSeek # Calculates acceleration to take an agent directly away from a target agent. +# Initializes the behavior func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void: pass diff --git a/project/src/Behaviors/GSTFollowPath.gd b/project/src/Behaviors/GSTFollowPath.gd index e3c649f..529f0e0 100644 --- a/project/src/Behaviors/GSTFollowPath.gd +++ b/project/src/Behaviors/GSTFollowPath.gd @@ -3,13 +3,19 @@ extends GSTArrive # Produces a linear acceleration that moves the agent along the specified path. +# The path to follow and travel along var path: GSTPath +# The distance along the path to generate the next target position. var path_offset := 0.0 +# Whether to use `GSTArrive` behavior on an open path. var arrive_enabled := true +# The amount of time in the future to predict the owning agent's position along the path. Setting +# it to 0 will force non-predictive path following. var prediction_time := 0.0 +# Initializes the behavior func _init( agent: GSTSteeringAgent, path: GSTPath, diff --git a/project/src/Behaviors/GSTLookWhereYouGo.gd b/project/src/Behaviors/GSTLookWhereYouGo.gd index 3057c1f..f1542c8 100644 --- a/project/src/Behaviors/GSTLookWhereYouGo.gd +++ b/project/src/Behaviors/GSTLookWhereYouGo.gd @@ -3,6 +3,7 @@ extends GSTMatchOrientation # Calculates an angular acceleration to match an agent's orientation to its direction of travel. +# Initializes the behavior func _init(agent: GSTSteeringAgent).(agent, null) -> void: pass diff --git a/project/src/Behaviors/GSTMatchOrientation.gd b/project/src/Behaviors/GSTMatchOrientation.gd index e8229db..e240733 100644 --- a/project/src/Behaviors/GSTMatchOrientation.gd +++ b/project/src/Behaviors/GSTMatchOrientation.gd @@ -4,12 +4,17 @@ extends GSTSteeringBehavior # The calculation will attempt to arrive with zero remaining angular velocity. +# The target orientation for the behavior to try and match rotations to var target: GSTAgentLocation +# The amount of distance in radians for the behavior to consider itself close enough to match var alignment_tolerance: float +# The amount of distance in radians from the goal to start slowing down var deceleration_radius: float +# A constant to represent the time it takes to change angular accelerations var time_to_reach: float = 0.1 +# Initializes the behavior func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: self.target = target diff --git a/project/src/Behaviors/GSTPriority.gd b/project/src/Behaviors/GSTPriority.gd index c3fd2bf..30baddf 100644 --- a/project/src/Behaviors/GSTPriority.gd +++ b/project/src/Behaviors/GSTPriority.gd @@ -1,23 +1,28 @@ class_name GSTPriority extends GSTSteeringBehavior -# Contains multiple steering behaviors and returns only the result of the first that has a non-zero - # acceleration. +# Contains multiple behaviors and returns only the result of the first with non-zero acceleration. var _behaviors := [] +# The index in the behavior array of the last behavior that was selected. var last_selected_index: int +# The amount of acceleration for a behavior to be considered to have effectively zero acceleration var zero_threshold: float +# Initializes the behavior func _init(agent: GSTSteeringAgent, zero_threshold := 0.001).(agent) -> void: self.zero_threshold = zero_threshold +# Add a steering `behavior` to the pool of behaviors to consider func add(behavior: GSTSteeringBehavior) -> void: _behaviors.append(behavior) +# Returns the behavior at the position in the pool referred to by `index`. +# Returns `null` if none were found. func get_behavior_at(index: int) -> GSTSteeringBehavior: if _behaviors.size() > index: return _behaviors[index] diff --git a/project/src/Behaviors/GSTPursue.gd b/project/src/Behaviors/GSTPursue.gd index 1bd4129..d4a4c9e 100644 --- a/project/src/Behaviors/GSTPursue.gd +++ b/project/src/Behaviors/GSTPursue.gd @@ -1,14 +1,16 @@ class_name GSTPursue extends GSTSteeringBehavior -# Calculates acceleration to take an agent to intersect with where a target agent will be. - -# # The `predict_time_max` variable represents how far ahead to calculate the intersection point. +# Calculates acceleration to take an agent to intersect with where a target agent will be, instead +# of where it currently is. +# The target agent that the behavior is trying to intercept var target: GSTSteeringAgent +# The maximum amount of time in the future for the behavior to predict the target's position var predict_time_max: float +# Initializes the behavior func _init( agent: GSTSteeringAgent, target: GSTSteeringAgent, diff --git a/project/src/Behaviors/GSTSeek.gd b/project/src/Behaviors/GSTSeek.gd index 6d09a5d..c2f6b49 100644 --- a/project/src/Behaviors/GSTSeek.gd +++ b/project/src/Behaviors/GSTSeek.gd @@ -1,11 +1,13 @@ class_name GSTSeek extends GSTSteeringBehavior -# Calculates acceleration to take an agent to a target agent's position as directly as possible +# Calculates acceleration to take an agent to a target agent's position directly +# The target that the behavior aims to move the agent to var target: GSTAgentLocation +# Initializes the behavior func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: self.target = target diff --git a/project/src/Behaviors/GSTSeparation.gd b/project/src/Behaviors/GSTSeparation.gd index e11e758..b8861af 100644 --- a/project/src/Behaviors/GSTSeparation.gd +++ b/project/src/Behaviors/GSTSeparation.gd @@ -1,18 +1,19 @@ class_name GSTSeparation extends GSTGroupBehavior -# Group behavior that produces acceleration repelling from the other neighbors that are in the -# immediate area defined by the given `GSTProximity`. - -# # The produced acceleration is an average of all agents under consideration, multiplied by a -# # strength decreasing by the inverse square law in relation to distance, and accumulated. -# # In effect, all neighbors produce a single repelling force. +# Group behavior that produces acceleration that repels the agent from the other neighbors that +# are in the area defined by the given `GSTProximity`. +# +# The produced acceleration is an average of all agents under consideration, multiplied by a +# strength decreasing by the inverse square law in relation to distance, and accumulated. +# The constant coefficient to calculate how fast the separation strength decays with distance. var decay_coefficient := 1.0 var acceleration: GSTTargetAcceleration +# Initializes the behavior func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void: pass diff --git a/project/src/GSTGroupBehavior.gd b/project/src/GSTGroupBehavior.gd index 309a8a2..71c7efa 100644 --- a/project/src/GSTGroupBehavior.gd +++ b/project/src/GSTGroupBehavior.gd @@ -9,7 +9,7 @@ var proximity: GSTProximity var _callback := funcref(self, "report_neighbor") -# Initializes the behavior with its owning `agent` and group's `proximity` +# Initializes the behavior func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void: self.proximity = proximity diff --git a/project/src/GSTSteeringBehavior.gd b/project/src/GSTSteeringBehavior.gd index b55b8e5..91020ba 100644 --- a/project/src/GSTSteeringBehavior.gd +++ b/project/src/GSTSteeringBehavior.gd @@ -1,6 +1,9 @@ class_name GSTSteeringBehavior # The base class for all steering behaviors to extend. A steering behavior calculates the linear # and/or angular acceleration to be applied to its owning agent +# +# The entry point for all behaviors is the `calculate_steering` function. Everything else is +# self-contained within the behavior. # Whether this behavior is enabled. All disabled behaviors return zero amounts of acceleration. @@ -10,7 +13,7 @@ var enabled := true var agent: GSTSteeringAgent -# Sets the behavior's owning `agent` +# Initializes the behavior func _init(agent: GSTSteeringAgent) -> void: self.agent = agent