mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +01:00
Add docstring to currently implemented code.
This commit is contained in:
parent
9b02baaba6
commit
7520939bdd
@ -1,5 +1,8 @@
|
|||||||
extends Reference
|
extends Reference
|
||||||
class_name AgentLocation
|
class_name AgentLocation
|
||||||
|
"""
|
||||||
|
Data type to represent an agent with a location and an orientation
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var position: = Vector3.ZERO
|
var position: = Vector3.ZERO
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
extends SteeringBehavior
|
extends SteeringBehavior
|
||||||
class_name Arrive
|
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
|
var target: AgentLocation
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
extends Pursue
|
extends Pursue
|
||||||
class_name Evade
|
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):
|
func _init(agent: SteeringAgent, target: SteeringAgent, max_predict_time: = 1.0).(agent, target, max_predict_time):
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
extends MatchOrientation
|
extends MatchOrientation
|
||||||
class_name Face
|
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:
|
func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void:
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
extends Seek
|
extends Seek
|
||||||
class_name Flee
|
class_name Flee
|
||||||
|
"""
|
||||||
|
Calculates acceleration to take an agent directly away from a target agent.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void:
|
func _init(agent: SteeringAgent, target: AgentLocation).(agent, target) -> void:
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
extends SteeringBehavior
|
extends SteeringBehavior
|
||||||
class_name MatchOrientation
|
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
|
var target: AgentLocation
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
extends SteeringBehavior
|
extends SteeringBehavior
|
||||||
class_name Pursue
|
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
|
var target: SteeringAgent
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
extends SteeringBehavior
|
extends SteeringBehavior
|
||||||
class_name Seek
|
class_name Seek
|
||||||
|
"""
|
||||||
|
Calculates acceleration to take an agent to a target agent's position as directly as possible
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var target: AgentLocation
|
var target: AgentLocation
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
"""
|
||||||
|
Draws the bounding box of the static body wall.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var rect: Rect2
|
var rect: Rect2
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
extends KinematicBody2D
|
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
|
onready var radius: = ($CollisionShape2D.shape as CircleShape2D).radius
|
||||||
@ -25,6 +28,9 @@ func _draw() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
if not player_agent:
|
||||||
|
return
|
||||||
|
|
||||||
_update_agent()
|
_update_agent()
|
||||||
accel = flee.calculate_steering(accel)
|
accel = flee.calculate_steering(accel)
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
"""
|
||||||
|
Class to control the player in basic left/right up/down movement.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
onready var _radius: = ($CollisionShape2D.shape as CircleShape2D).radius
|
onready var _radius: = ($CollisionShape2D.shape as CircleShape2D).radius
|
||||||
|
@ -71,10 +71,8 @@ shape = SubResource( 3 )
|
|||||||
[node name="SeekerSpawner" type="Node2D" parent="."]
|
[node name="SeekerSpawner" type="Node2D" parent="."]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
agent_scene = ExtResource( 4 )
|
agent_scene = ExtResource( 4 )
|
||||||
player = NodePath("../Player")
|
|
||||||
|
|
||||||
[node name="FleeerSpawner" type="Node2D" parent="."]
|
[node name="FleeerSpawner" type="Node2D" parent="."]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
agent_scene = ExtResource( 6 )
|
agent_scene = ExtResource( 6 )
|
||||||
player = NodePath("../Player")
|
|
||||||
agent_color = Color( 0.0980392, 0.886275, 0.517647, 1 )
|
agent_color = Color( 0.0980392, 0.886275, 0.517647, 1 )
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
|
"""
|
||||||
|
Access helper class for children to access window boundaries.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var camera_boundaries: Rect2
|
var camera_boundaries: Rect2
|
||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
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"])
|
||||||
|
)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
extends KinematicBody2D
|
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
|
onready var radius: = ($CollisionShape2D.shape as CircleShape2D).radius
|
||||||
@ -25,6 +28,9 @@ func _draw() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
if not player_agent:
|
||||||
|
return
|
||||||
|
|
||||||
_update_agent()
|
_update_agent()
|
||||||
accel = seek.calculate_steering(accel)
|
accel = seek.calculate_steering(accel)
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
extends Node2D
|
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(PackedScene) var agent_scene: PackedScene
|
||||||
export var agent_count: = 10
|
export var agent_count: = 10
|
||||||
export var player: = NodePath()
|
|
||||||
export var min_speed: = 50.0
|
export var min_speed: = 50.0
|
||||||
export var max_speed: = 125.0
|
export var max_speed: = 125.0
|
||||||
export var agent_color: = Color.blue
|
export var agent_color: = Color.blue
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
extends AgentLocation
|
extends AgentLocation
|
||||||
class_name SteeringAgent
|
class_name SteeringAgent
|
||||||
|
"""
|
||||||
|
Extended agent data type that adds velocity and speed data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var zero_linear_speed_threshold: = 0.01
|
var zero_linear_speed_threshold: = 0.01
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
extends Reference
|
extends Reference
|
||||||
class_name SteeringBehavior
|
class_name SteeringBehavior
|
||||||
|
"""
|
||||||
|
Base class to calculate how an AI agent steers itself.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var enabled: = true
|
var enabled: = true
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
extends Reference
|
extends Reference
|
||||||
class_name TargetAcceleration
|
class_name TargetAcceleration
|
||||||
|
"""
|
||||||
|
A linear and angular amount of acceleration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
var linear: = Vector3.ZERO
|
var linear: = Vector3.ZERO
|
||||||
|
Loading…
Reference in New Issue
Block a user