Add documentation strings to behaviors

This commit is contained in:
Francois Belair 2020-01-27 13:24:05 -05:00
parent 5f6dd15c0e
commit 2d8bdaebd7
16 changed files with 58 additions and 22 deletions

View File

@ -4,12 +4,17 @@ extends GSTSteeringBehavior
# The calculation will attempt to arrive with zero remaining velocity. # 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 var target: GSTAgentLocation
# The distance from the target for the agent to be considered successfully arrived
var arrival_tolerance: float var arrival_tolerance: float
# The distance from the target for the agent to begin slowing down
var deceleration_radius: float var deceleration_radius: float
# A constant that represents the time it takes to change acceleration
var time_to_reach := 0.1 var time_to_reach := 0.1
# Initializes the behavior
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void:
self.target = target self.target = target

View File

@ -1,6 +1,6 @@
class_name GSTAvoidCollisions class_name GSTAvoidCollisions
extends GSTGroupBehavior 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 var first_neighbor: GSTSteeringAgent
@ -11,6 +11,7 @@ var first_relative_position: Vector3
var first_relative_velocity: Vector3 var first_relative_velocity: Vector3
# Intializes the behavior
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void: func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void:
pass pass

View File

@ -1,11 +1,11 @@
class_name GSTBlend class_name GSTBlend
extends GSTSteeringBehavior extends GSTSteeringBehavior
# Blends multiple steering behaviors into one, and returns acceleration combining all of them. # 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. # 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. # `GSTSteeringBehavior` and a `weight` key with a value of type float.
@ -13,15 +13,18 @@ var _behaviors := []
var _accel := GSTTargetAcceleration.new() var _accel := GSTTargetAcceleration.new()
# Initializes the behavior
func _init(agent: GSTSteeringAgent).(agent) -> void: func _init(agent: GSTSteeringAgent).(agent) -> void:
pass 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: func add(behavior: GSTSteeringBehavior, weight: float) -> void:
behavior.agent = agent behavior.agent = agent
_behaviors.append({behavior = behavior, weight = weight}) _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: func get_behavior_at(index: int) -> Dictionary:
if _behaviors.size() > index: if _behaviors.size() > index:
return _behaviors[index] return _behaviors[index]

View File

@ -1,12 +1,13 @@
class_name GSTCohesion class_name GSTCohesion
extends GSTGroupBehavior extends GSTGroupBehavior
# Group behavior that produces linear acceleration that attempts to move the agent towards the # 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 var center_of_mass: Vector3
# Initializes the behavior
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void: func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void:
pass pass

View File

@ -2,9 +2,8 @@ class_name GSTEvade
extends GSTPursue extends GSTPursue
# Calculates acceleration to take an agent away from where a target agent will be. # 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( func _init(
agent: GSTSteeringAgent, agent: GSTSteeringAgent,
target: GSTSteeringAgent, target: GSTSteeringAgent,

View File

@ -4,6 +4,7 @@ extends GSTMatchOrientation
# The acceleration will attempt to arrive with zero remaining angular velocity. # The acceleration will attempt to arrive with zero remaining angular velocity.
# Initializes the behavior
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void: func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void:
pass pass

View File

@ -3,6 +3,7 @@ extends GSTSeek
# Calculates acceleration to take an agent directly away from a target agent. # Calculates acceleration to take an agent directly away from a target agent.
# Initializes the behavior
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void: func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void:
pass pass

View File

@ -3,13 +3,19 @@ extends GSTArrive
# Produces a linear acceleration that moves the agent along the specified path. # Produces a linear acceleration that moves the agent along the specified path.
# The path to follow and travel along
var path: GSTPath var path: GSTPath
# The distance along the path to generate the next target position.
var path_offset := 0.0 var path_offset := 0.0
# Whether to use `GSTArrive` behavior on an open path.
var arrive_enabled := true 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 var prediction_time := 0.0
# Initializes the behavior
func _init( func _init(
agent: GSTSteeringAgent, agent: GSTSteeringAgent,
path: GSTPath, path: GSTPath,

View File

@ -3,6 +3,7 @@ extends GSTMatchOrientation
# Calculates an angular acceleration to match an agent's orientation to its direction of travel. # 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: func _init(agent: GSTSteeringAgent).(agent, null) -> void:
pass pass

View File

@ -4,12 +4,17 @@ extends GSTSteeringBehavior
# The calculation will attempt to arrive with zero remaining angular velocity. # 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 var target: GSTAgentLocation
# The amount of distance in radians for the behavior to consider itself close enough to match
var alignment_tolerance: float var alignment_tolerance: float
# The amount of distance in radians from the goal to start slowing down
var deceleration_radius: float var deceleration_radius: float
# A constant to represent the time it takes to change angular accelerations
var time_to_reach: float = 0.1 var time_to_reach: float = 0.1
# Initializes the behavior
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void:
self.target = target self.target = target

View File

@ -1,23 +1,28 @@
class_name GSTPriority class_name GSTPriority
extends GSTSteeringBehavior extends GSTSteeringBehavior
# Contains multiple steering behaviors and returns only the result of the first that has a non-zero # Contains multiple behaviors and returns only the result of the first with non-zero acceleration.
# acceleration.
var _behaviors := [] var _behaviors := []
# The index in the behavior array of the last behavior that was selected.
var last_selected_index: int var last_selected_index: int
# The amount of acceleration for a behavior to be considered to have effectively zero acceleration
var zero_threshold: float var zero_threshold: float
# Initializes the behavior
func _init(agent: GSTSteeringAgent, zero_threshold := 0.001).(agent) -> void: func _init(agent: GSTSteeringAgent, zero_threshold := 0.001).(agent) -> void:
self.zero_threshold = zero_threshold self.zero_threshold = zero_threshold
# Add a steering `behavior` to the pool of behaviors to consider
func add(behavior: GSTSteeringBehavior) -> void: func add(behavior: GSTSteeringBehavior) -> void:
_behaviors.append(behavior) _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: func get_behavior_at(index: int) -> GSTSteeringBehavior:
if _behaviors.size() > index: if _behaviors.size() > index:
return _behaviors[index] return _behaviors[index]

View File

@ -1,14 +1,16 @@
class_name GSTPursue class_name GSTPursue
extends GSTSteeringBehavior extends GSTSteeringBehavior
# Calculates acceleration to take an agent to intersect with where a target agent will be. # Calculates acceleration to take an agent to intersect with where a target agent will be, instead
# of where it currently is.
# # The `predict_time_max` variable represents how far ahead to calculate the intersection point.
# The target agent that the behavior is trying to intercept
var target: GSTSteeringAgent 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 var predict_time_max: float
# Initializes the behavior
func _init( func _init(
agent: GSTSteeringAgent, agent: GSTSteeringAgent,
target: GSTSteeringAgent, target: GSTSteeringAgent,

View File

@ -1,11 +1,13 @@
class_name GSTSeek class_name GSTSeek
extends GSTSteeringBehavior 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 var target: GSTAgentLocation
# Initializes the behavior
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void: func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void:
self.target = target self.target = target

View File

@ -1,18 +1,19 @@
class_name GSTSeparation class_name GSTSeparation
extends GSTGroupBehavior extends GSTGroupBehavior
# Group behavior that produces acceleration repelling from the other neighbors that are in the # Group behavior that produces acceleration that repels the agent from the other neighbors that
# immediate area defined by the given `GSTProximity`. # are in the area defined by the given `GSTProximity`.
#
# # The produced acceleration is an average of all agents under consideration, multiplied by a # 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. # strength decreasing by the inverse square law in relation to distance, and accumulated.
# # In effect, all neighbors produce a single repelling force.
# The constant coefficient to calculate how fast the separation strength decays with distance.
var decay_coefficient := 1.0 var decay_coefficient := 1.0
var acceleration: GSTTargetAcceleration var acceleration: GSTTargetAcceleration
# Initializes the behavior
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void: func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void:
pass pass

View File

@ -9,7 +9,7 @@ var proximity: GSTProximity
var _callback := funcref(self, "report_neighbor") 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: func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void:
self.proximity = proximity self.proximity = proximity

View File

@ -1,6 +1,9 @@
class_name GSTSteeringBehavior class_name GSTSteeringBehavior
# The base class for all steering behaviors to extend. A steering behavior calculates the linear # 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 # 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. # Whether this behavior is enabled. All disabled behaviors return zero amounts of acceleration.
@ -10,7 +13,7 @@ var enabled := true
var agent: GSTSteeringAgent var agent: GSTSteeringAgent
# Sets the behavior's owning `agent` # Initializes the behavior
func _init(agent: GSTSteeringAgent) -> void: func _init(agent: GSTSteeringAgent) -> void:
self.agent = agent self.agent = agent