mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-10 00:52:10 +01:00
Add documentation strings to behaviors
This commit is contained in:
parent
5f6dd15c0e
commit
2d8bdaebd7
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user