Edit docstrings in src/Behaviors

This commit is contained in:
Nathan Lovato 2020-01-29 10:04:04 -06:00
parent 4885707145
commit bd41d5987c
16 changed files with 125 additions and 113 deletions

View File

@ -1,16 +1,17 @@
# Calculates acceleration to take an agent to its target's location. # Calculates acceleration to take an agent to its target's location. The
# The calculation will attempt to arrive with zero remaining velocity. # calculation attempts to arrive with zero remaining velocity.
class_name GSTArrive class_name GSTArrive
extends GSTSteeringBehavior extends GSTSteeringBehavior
# The target whose location the agent will be steered to arrive at # Target agent to arrive to.
var target: GSTAgentLocation var target: GSTAgentLocation
# The distance from the target for the agent to be considered successfully arrived # 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 # Distance from the target for the agent to begin slowing down.
var deceleration_radius: float var deceleration_radius: float
# The amount of time to reach the target velocity # Represents the time it takes to change acceleration.
var time_to_reach := 0.1 var time_to_reach := 0.1

View File

@ -1,4 +1,5 @@
# Behavior that steers the agent to avoid obstacles lying in its path as approximated by spheres. # Steers the agent to avoid obstacles in its path. Approximates obstacles as
# spheres.
class_name GSTAvoidCollisions class_name GSTAvoidCollisions
extends GSTGroupBehavior extends GSTGroupBehavior

View File

@ -1,10 +1,11 @@
# Blends multiple steering behaviors into one, and returns acceleration combining all of them. # Blends multiple steering behaviors into one, and returns a weighted
# acceleration from their calculations.
# #
# Each behavior is associated with a weight - a modifier by which the result will be multiplied by, # Stores the behaviors internally as dictionaries of the form
# then added to a total acceleration. # {
# # behavior : GSTSteeringBehavior,
# Each behavior is stored internally as a `Dictionary` with a `behavior` key with a value of type # weight : float
# `GSTSteeringBehavior` and a `weight` key with a value of type float. # }
class_name GSTBlend class_name GSTBlend
extends GSTSteeringBehavior extends GSTSteeringBehavior
@ -17,13 +18,14 @@ 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 # Appends a behavior to the internal array along with its `weight`.
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. # Returns the behavior at the specified `index`, or 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,5 +1,5 @@
# Group behavior that produces linear acceleration that attempts to move the agent towards the # Calculates an acceleration that attempts to move the agent towards the center
# center of mass of the agents in the area defined by the Proximity. # of mass of the agents in the area defined by the `GSTProximity`.
class_name GSTCohesion class_name GSTCohesion
extends GSTGroupBehavior extends GSTGroupBehavior

View File

@ -1,4 +1,5 @@
# 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 is
# moving.
class_name GSTEvade class_name GSTEvade
extends GSTPursue extends GSTPursue

View File

@ -1,5 +1,5 @@
# Calculates angular acceleration to rotate a target to face its target's position. # Calculates angular acceleration to rotate a target to face its target's
# The acceleration will attempt to arrive with zero remaining angular velocity. # position. The behavior attemps to arrive with zero remaining angular velocity.
class_name GSTFace class_name GSTFace
extends GSTMatchOrientation extends GSTMatchOrientation

View File

@ -3,15 +3,15 @@ class_name GSTFollowPath
extends GSTArrive extends GSTArrive
# The path to follow and travel along # The path to follow and travel along.
var path: GSTPath var path: GSTPath
# The distance along the path to generate the next target position. # 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. # 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 # The amount of time in the future to predict the owning agent's position along
# it to 0 will force non-predictive path following. # the path. Setting it to 0.0 will force non-predictive path following.
var prediction_time := 0.0 var prediction_time := 0.0

View File

@ -1,4 +1,5 @@
# 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.
class_name GSTLookWhereYouGo class_name GSTLookWhereYouGo
extends GSTMatchOrientation extends GSTMatchOrientation

View File

@ -1,14 +1,16 @@
# Calculates an angular acceleration to match an agent's orientation to its target's. # Calculates an angular acceleration to match an agent's orientation to that of
# The calculation will attempt to arrive with zero remaining angular velocity. # its target. Attempts to make the agent arrive with zero remaining angular
# velocity.
class_name GSTMatchOrientation class_name GSTMatchOrientation
extends GSTSteeringBehavior extends GSTSteeringBehavior
# The target orientation for the behavior to try and match rotations to # 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 # The amount of distance in radians for the behavior to consider itself close
# enough to be matching the target agent's rotation.
var alignment_tolerance: float var alignment_tolerance: float
# The amount of distance in radians from the goal to start slowing down # The amount of distance in radians from the goal to start slowing down.
var deceleration_radius: float var deceleration_radius: float
# The amount of time to reach the target velocity # The amount of time to reach the target velocity
var time_to_reach: float = 0.1 var time_to_reach: float = 0.1

View File

@ -1,13 +1,15 @@
# Contains multiple behaviors and returns only the result of the first with non-zero acceleration. # Container for multiple behaviors that returns the result of the first child
# behavior with non-zero acceleration.
class_name GSTPriority class_name GSTPriority
extends GSTSteeringBehavior extends GSTSteeringBehavior
var _behaviors := [] var _behaviors := []
# The index in the behavior array of the last behavior that was selected. # The index of the last behavior the container prioritized.
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 # If a behavior's acceleration is lower than this threshold, the container
# considers it has an acceleration of zero.
var zero_threshold: float var zero_threshold: float
@ -15,13 +17,13 @@ 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 # Appends a steering behavior as a child of this container.
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 the behavior at the position in the pool referred to by `index`, or
# Returns `null` if none were found. # `null` if no behavior was 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,12 +1,13 @@
# Calculates acceleration to take an agent to intersect with where a target agent will be, instead # Calculates an acceleration to make an agent intercept another based on the
# of where it currently is. # target agent's movement.
class_name GSTPursue class_name GSTPursue
extends GSTSteeringBehavior extends GSTSteeringBehavior
# The target agent that the behavior is trying to intercept # 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 # The maximum amount of time in the future the behavior predicts the target's
# location.
var predict_time_max: float var predict_time_max: float

View File

@ -1,9 +1,10 @@
# Calculates acceleration to take an agent to a target agent's position directly # Calculates an acceleration to take an agent to a target agent's position
# directly.
class_name GSTSeek class_name GSTSeek
extends GSTSteeringBehavior extends GSTSteeringBehavior
# The target that the behavior aims to move the agent to # The target that the behavior aims to move the agent to.
var target: GSTAgentLocation var target: GSTAgentLocation

View File

@ -1,15 +1,16 @@
# Group behavior that produces acceleration that repels the agent from the other neighbors that # Calculates an acceleration that repels the agent from its neighbors in the
# are in the area defined by the given `GSTProximity`. # given `GSTProximity`.
# #
# The produced acceleration is an average of all agents under consideration, multiplied by a # The acceleration is an average based on all neighbors, 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 it
# accumulates.
class_name GSTSeparation class_name GSTSeparation
extends GSTGroupBehavior extends GSTGroupBehavior
# The coefficient to calculate how fast the separation strength decays with distance. # The coefficient to calculate how fast the separation strength decays with distance.
var decay_coefficient := 1.0 var decay_coefficient := 1.0
# Container for the calculated acceleration.
var acceleration: GSTTargetAcceleration var acceleration: GSTTargetAcceleration

View File

@ -1,7 +1,6 @@
# Represents a path made up of Vector3 waypoints, split into path segments for use by path # Represents a path made up of Vector3 waypoints, split into segments path
# following behaviors. # follow behaviors can use.
extends Reference extends Reference class_name GSTPath
class_name GSTPath
# If `false`, the path loops. # If `false`, the path loops.