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.
# The calculation will attempt to arrive with zero remaining velocity.
# Calculates acceleration to take an agent to its target's location. The
# calculation attempts to arrive with zero remaining velocity.
class_name GSTArrive
extends GSTSteeringBehavior
# The target whose location the agent will be steered to arrive at
# Target agent to arrive to.
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
# 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
# The amount of time to reach the target velocity
# Represents the time it takes to change acceleration.
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
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,
# then added to a total acceleration.
#
# 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.
# Stores the behaviors internally as dictionaries of the form
# {
# behavior : GSTSteeringBehavior,
# weight : float
# }
class_name GSTBlend
extends GSTSteeringBehavior
@ -17,13 +18,14 @@ 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
# Appends a behavior to the internal array along with its `weight`.
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.
# Returns the behavior at the specified `index`, or an empty `Dictionary` if
# none was found.
func get_behavior_at(index: int) -> Dictionary:
if _behaviors.size() > index:
return _behaviors[index]

View File

@ -1,5 +1,5 @@
# 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 Proximity.
# Calculates an acceleration that attempts to move the agent towards the center
# of mass of the agents in the area defined by the `GSTProximity`.
class_name GSTCohesion
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
extends GSTPursue

View File

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

View File

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

View File

@ -1,14 +1,16 @@
# Calculates an angular acceleration to match an agent's orientation to its target's.
# The calculation will attempt to arrive with zero remaining angular velocity.
# Calculates an angular acceleration to match an agent's orientation to that of
# its target. Attempts to make the agent arrive with zero remaining angular
# velocity.
class_name GSTMatchOrientation
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
# 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
# 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
# The amount of time to reach the target velocity
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
extends GSTSteeringBehavior
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
# 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
@ -15,13 +17,13 @@ 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
# Appends a steering behavior as a child of this container.
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.
# Returns the behavior at the position in the pool referred to by `index`, or
# `null` if no behavior was found.
func get_behavior_at(index: int) -> GSTSteeringBehavior:
if _behaviors.size() > 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
# of where it currently is.
# Calculates an acceleration to make an agent intercept another based on the
# target agent's movement.
class_name GSTPursue
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
# 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

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
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

View File

@ -1,15 +1,16 @@
# Group behavior that produces acceleration that repels the agent from the other neighbors that
# are in the area defined by the given `GSTProximity`.
# Calculates an acceleration that repels the agent from its neighbors in 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 acceleration is an average based on all neighbors, multiplied by a
# strength decreasing by the inverse square law in relation to distance, and it
# accumulates.
class_name GSTSeparation
extends GSTGroupBehavior
# The coefficient to calculate how fast the separation strength decays with distance.
var decay_coefficient := 1.0
# Container for the calculated acceleration.
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
# following behaviors.
extends Reference
class_name GSTPath
# Represents a path made up of Vector3 waypoints, split into segments path
# follow behaviors can use.
extends Reference class_name GSTPath
# If `false`, the path loops.