diff --git a/src/Steering/AgentLocation.gd b/src/Steering/AgentLocation.gd index 2eecad8..e0cea19 100644 --- a/src/Steering/AgentLocation.gd +++ b/src/Steering/AgentLocation.gd @@ -1,5 +1,8 @@ extends Reference class_name AgentLocation +""" +Data type to represent an agent with a location and an orientation +""" var position: = Vector3.ZERO diff --git a/src/Steering/Behaviors/Arrive.gd b/src/Steering/Behaviors/Arrive.gd index f5dd188..e972990 100644 --- a/src/Steering/Behaviors/Arrive.gd +++ b/src/Steering/Behaviors/Arrive.gd @@ -1,5 +1,9 @@ extends SteeringBehavior class_name Arrive +""" +Calculates acceleration to take an agent to its target's location. +The calculation will attempt to arrive with zero remaining velocity. +""" var target: AgentLocation diff --git a/src/Steering/Behaviors/Evade.gd b/src/Steering/Behaviors/Evade.gd index 50a73a5..091d48d 100644 --- a/src/Steering/Behaviors/Evade.gd +++ b/src/Steering/Behaviors/Evade.gd @@ -1,5 +1,10 @@ extends Pursue class_name Evade +""" +Calculates acceleration to take an agent away from where a target agent will be. + +The `max_predict_time` variable represents how far ahead to calculate the intersection point. +""" func _init(agent: SteeringAgent, target: SteeringAgent, max_predict_time: = 1.0).(agent, target, max_predict_time): diff --git a/src/Steering/Behaviors/Face.gd b/src/Steering/Behaviors/Face.gd index 453187a..e80ee5b 100644 --- a/src/Steering/Behaviors/Face.gd +++ b/src/Steering/Behaviors/Face.gd @@ -1,5 +1,9 @@ extends MatchOrientation class_name Face +""" +Calculates angular acceleration to rotate a target to face its target's position. +The acceleration will attempt to arrive with zero remaining angular velocity. +""" func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void: diff --git a/src/Steering/Behaviors/Flee.gd b/src/Steering/Behaviors/Flee.gd index 6e9d286..f3fba43 100644 --- a/src/Steering/Behaviors/Flee.gd +++ b/src/Steering/Behaviors/Flee.gd @@ -1,5 +1,8 @@ extends Seek class_name Flee +""" +Calculates acceleration to take an agent directly away from a target agent. +""" func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void: diff --git a/src/Steering/Behaviors/MatchOrientation.gd b/src/Steering/Behaviors/MatchOrientation.gd index f536bb4..fa7b6ca 100644 --- a/src/Steering/Behaviors/MatchOrientation.gd +++ b/src/Steering/Behaviors/MatchOrientation.gd @@ -1,5 +1,9 @@ extends SteeringBehavior class_name MatchOrientation +""" +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. +""" var target: AgentLocation diff --git a/src/Steering/Behaviors/Pursue.gd b/src/Steering/Behaviors/Pursue.gd index d40ec7f..9124c72 100644 --- a/src/Steering/Behaviors/Pursue.gd +++ b/src/Steering/Behaviors/Pursue.gd @@ -1,5 +1,10 @@ extends SteeringBehavior class_name Pursue +""" +Calculates acceleration to take an agent to intersect with where a target agent will be. + +The `max_predict_time` variable represents how far ahead to calculate the intersection point. +""" var target: SteeringAgent diff --git a/src/Steering/Behaviors/Seek.gd b/src/Steering/Behaviors/Seek.gd index 9f95536..610a6c1 100644 --- a/src/Steering/Behaviors/Seek.gd +++ b/src/Steering/Behaviors/Seek.gd @@ -1,5 +1,8 @@ extends SteeringBehavior class_name Seek +""" +Calculates acceleration to take an agent to a target agent's position as directly as possible +""" var target: AgentLocation diff --git a/src/Steering/Demos/SeekFlee/Boundary.gd b/src/Steering/Demos/SeekFlee/Boundary.gd index a9439e5..7bef08e 100644 --- a/src/Steering/Demos/SeekFlee/Boundary.gd +++ b/src/Steering/Demos/SeekFlee/Boundary.gd @@ -1,4 +1,7 @@ extends StaticBody2D +""" +Draws the bounding box of the static body wall. +""" var rect: Rect2 diff --git a/src/Steering/Demos/SeekFlee/Coward.gd b/src/Steering/Demos/SeekFlee/Coward.gd index f623504..b596ee1 100644 --- a/src/Steering/Demos/SeekFlee/Coward.gd +++ b/src/Steering/Demos/SeekFlee/Coward.gd @@ -1,4 +1,7 @@ extends KinematicBody2D +""" +AI agent that seeks to move away from the player's location as directly as possible. +""" onready var radius: = ($CollisionShape2D.shape as CircleShape2D).radius @@ -25,6 +28,9 @@ func _draw() -> void: func _physics_process(delta: float) -> void: + if not player_agent: + return + _update_agent() accel = flee.calculate_steering(accel) diff --git a/src/Steering/Demos/SeekFlee/Player.gd b/src/Steering/Demos/SeekFlee/Player.gd index 5a7ab70..00ef813 100644 --- a/src/Steering/Demos/SeekFlee/Player.gd +++ b/src/Steering/Demos/SeekFlee/Player.gd @@ -1,4 +1,7 @@ extends KinematicBody2D +""" +Class to control the player in basic left/right up/down movement. +""" onready var _radius: = ($CollisionShape2D.shape as CircleShape2D).radius diff --git a/src/Steering/Demos/SeekFlee/SeekFlee.tscn b/src/Steering/Demos/SeekFlee/SeekFlee.tscn index d191561..09a2cad 100644 --- a/src/Steering/Demos/SeekFlee/SeekFlee.tscn +++ b/src/Steering/Demos/SeekFlee/SeekFlee.tscn @@ -71,10 +71,8 @@ shape = SubResource( 3 ) [node name="SeekerSpawner" type="Node2D" parent="."] script = ExtResource( 2 ) agent_scene = ExtResource( 4 ) -player = NodePath("../Player") [node name="FleeerSpawner" type="Node2D" parent="."] script = ExtResource( 2 ) agent_scene = ExtResource( 6 ) -player = NodePath("../Player") agent_color = Color( 0.0980392, 0.886275, 0.517647, 1 ) diff --git a/src/Steering/Demos/SeekFlee/SeekFleeDemo.gd b/src/Steering/Demos/SeekFlee/SeekFleeDemo.gd index f92ff1d..5f01a2c 100644 --- a/src/Steering/Demos/SeekFlee/SeekFleeDemo.gd +++ b/src/Steering/Demos/SeekFlee/SeekFleeDemo.gd @@ -1,8 +1,14 @@ extends Node2D +""" +Access helper class for children to access window boundaries. +""" var camera_boundaries: Rect2 func _init() -> void: - camera_boundaries = Rect2(Vector2.ZERO, Vector2(ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"])) + camera_boundaries = Rect2( + Vector2.ZERO, + Vector2(ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"]) + ) diff --git a/src/Steering/Demos/SeekFlee/Seeker.gd b/src/Steering/Demos/SeekFlee/Seeker.gd index 759873f..3ec5946 100644 --- a/src/Steering/Demos/SeekFlee/Seeker.gd +++ b/src/Steering/Demos/SeekFlee/Seeker.gd @@ -1,4 +1,7 @@ extends KinematicBody2D +""" +AI agent that uses the Seek behavior to hone in on the player's location as directly as possible. +""" onready var radius: = ($CollisionShape2D.shape as CircleShape2D).radius @@ -25,6 +28,9 @@ func _draw() -> void: func _physics_process(delta: float) -> void: + if not player_agent: + return + _update_agent() accel = seek.calculate_steering(accel) diff --git a/src/Steering/Demos/SeekFlee/Spawner.gd b/src/Steering/Demos/SeekFlee/Spawner.gd index afddacc..e94c5df 100644 --- a/src/Steering/Demos/SeekFlee/Spawner.gd +++ b/src/Steering/Demos/SeekFlee/Spawner.gd @@ -1,12 +1,14 @@ extends Node2D +""" +Instantiates and configures a number of agent scenes within the level boundaries. +""" -onready var player_agent: AgentLocation = get_node(player).player_agent +onready var player_agent: AgentLocation = owner.get_node("Player").player_agent export(PackedScene) var agent_scene: PackedScene export var agent_count: = 10 -export var player: = NodePath() export var min_speed: = 50.0 export var max_speed: = 125.0 export var agent_color: = Color.blue diff --git a/src/Steering/SteeringAgent.gd b/src/Steering/SteeringAgent.gd index 7ad60c8..3f9a06c 100644 --- a/src/Steering/SteeringAgent.gd +++ b/src/Steering/SteeringAgent.gd @@ -1,5 +1,8 @@ extends AgentLocation class_name SteeringAgent +""" +Extended agent data type that adds velocity and speed data. +""" var zero_linear_speed_threshold: = 0.01 diff --git a/src/Steering/SteeringBehavior.gd b/src/Steering/SteeringBehavior.gd index 6d3e8ab..dfb8c54 100644 --- a/src/Steering/SteeringBehavior.gd +++ b/src/Steering/SteeringBehavior.gd @@ -1,5 +1,8 @@ extends Reference class_name SteeringBehavior +""" +Base class to calculate how an AI agent steers itself. +""" var enabled: = true diff --git a/src/Steering/TargetAcceleration.gd b/src/Steering/TargetAcceleration.gd index ccc6472..2a2a937 100644 --- a/src/Steering/TargetAcceleration.gd +++ b/src/Steering/TargetAcceleration.gd @@ -1,5 +1,8 @@ extends Reference class_name TargetAcceleration +""" +A linear and angular amount of acceleration. +""" var linear: = Vector3.ZERO