Format the code using gdformat

gdformat follows the official style guide, and handles line length and wrapping
lines for us.
This commit is contained in:
Nathan Lovato 2020-02-14 10:35:18 -06:00
parent 2940442b95
commit 68b85bb234
64 changed files with 337 additions and 423 deletions

View File

@ -1,22 +1,16 @@
extends Node extends Node
export (float, 0, 2000, 40) var linear_speed_max := 800.0 setget set_linear_speed_max
export(float, 0, 2000, 40) var linear_speed_max := 800.0 setget set_linear_speed_max export (float, 0, 200, 2.0) var linear_acceleration_max := 80.0 setget set_linear_acceleration_max
export(float, 0, 200, 2.0) var linear_acceleration_max := 80.0 setget set_linear_acceleration_max export (float, 0, 100, 0.1) var arrival_tolerance := 25.0 setget set_arrival_tolerance
export(float, 0, 100, 0.1) var arrival_tolerance := 25.0 setget set_arrival_tolerance export (float, 0, 500, 10) var deceleration_radius := 125.0 setget set_deceleration_radius
export(float, 0, 500, 10) var deceleration_radius := 125.0 setget set_deceleration_radius
onready var arriver := $Arriver onready var arriver := $Arriver
onready var target_drawer := $TargetDrawer onready var target_drawer := $TargetDrawer
func _ready() -> void: func _ready() -> void:
arriver.setup( arriver.setup(linear_speed_max, linear_acceleration_max, arrival_tolerance, deceleration_radius)
linear_speed_max,
linear_acceleration_max,
arrival_tolerance,
deceleration_radius
)
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
var agent := GSAIKinematicBody2DAgent.new(self) var agent := GSAIKinematicBody2DAgent.new(self)
var target := GSAIAgentLocation.new() var target := GSAIAgentLocation.new()
var arrive := GSAIArrive.new(agent, target) var arrive := GSAIArrive.new(agent, target)

View File

@ -1,6 +1,5 @@
extends Node2D extends Node2D
const COLORS := { const COLORS := {
deceleration_radius = Color(1.0, 0.419, 0.592, 0.5), deceleration_radius = Color(1.0, 0.419, 0.592, 0.5),
arrival_tolerance = Color(0.278, 0.231, 0.47, 0.3) arrival_tolerance = Color(0.278, 0.231, 0.47, 0.3)

View File

@ -1,6 +1,5 @@
extends Camera extends Camera
var target: Spatial var target: Spatial
onready var ray := $RayCast onready var ray := $RayCast

View File

@ -1,14 +1,13 @@
extends Node extends Node
export (float, 0, 50, 0.1) var linear_speed_max := 10.0 setget set_linear_speed_max
export(float, 0, 50, 0.1) var linear_speed_max := 10.0 setget set_linear_speed_max export (float, 0, 50, 0.1) var linear_acceleration_max := 1.0 setget set_linear_acceleration_max
export(float, 0, 50, 0.1) var linear_acceleration_max := 1.0 setget set_linear_acceleration_max export (float, 0, 50, 0.1) var arrival_tolerance := 0.5 setget set_arrival_tolerance
export(float, 0, 50, 0.1) var arrival_tolerance := 0.5 setget set_arrival_tolerance export (float, 0, 50, 0.1) var deceleration_radius := 5.0 setget set_deceleration_radius
export(float, 0, 50, 0.1) var deceleration_radius := 5.0 setget set_deceleration_radius export (int, 0, 359, 2) var angular_speed_max := 270 setget set_angular_speed_max
export(int, 0, 359, 2) var angular_speed_max := 270 setget set_angular_speed_max export (int, 0, 359, 2) var angular_accel_max := 45 setget set_angular_accel_max
export(int, 0, 359, 2) var angular_accel_max := 45 setget set_angular_accel_max export (int, 0, 180, 2) var align_tolerance := 5 setget set_align_tolerance
export(int, 0, 180, 2) var align_tolerance := 5 setget set_align_tolerance export (int, 0, 359, 2) var angular_deceleration_radius := 45 setget set_angular_deceleration_radius
export(int, 0, 359, 2) var angular_deceleration_radius := 45 setget set_angular_deceleration_radius
onready var target := $MouseTarget onready var target := $MouseTarget
onready var arriver := $Arriver onready var arriver := $Arriver

View File

@ -1,6 +1,5 @@
extends KinematicBody extends KinematicBody
var target_node: Spatial var target_node: Spatial
onready var agent := GSAIKinematicBody3DAgent.new(self) onready var agent := GSAIKinematicBody3DAgent.new(self)
@ -28,7 +27,7 @@ func setup(
linear_acceleration_max: float, linear_acceleration_max: float,
linear_speed_max: float, linear_speed_max: float,
_target: Spatial _target: Spatial
) -> void: ) -> void:
agent.linear_speed_max = linear_speed_max agent.linear_speed_max = linear_speed_max
agent.linear_acceleration_max = linear_acceleration_max agent.linear_acceleration_max = linear_acceleration_max
agent.linear_drag_percentage = 0.05 agent.linear_drag_percentage = 0.05

View File

@ -1,9 +1,8 @@
extends Node extends Node
export (float, 0, 2000, 40) var linear_speed_max := 350.0 setget set_linear_speed_max
export(float, 0, 2000, 40) var linear_speed_max := 350.0 setget set_linear_speed_max export (float, 0, 100, 2) var linear_acceleration_max := 40.0 setget set_linear_accel_max
export(float, 0, 100, 2) var linear_acceleration_max := 40.0 setget set_linear_accel_max export (float, 0, 500, 10) var proximity_radius := 140.0 setget set_proximity_radius
export(float, 0, 500, 10) var proximity_radius := 140.0 setget set_proximity_radius
export var draw_proximity := true setget set_draw_proximity export var draw_proximity := true setget set_draw_proximity
onready var spawner := $Spawner onready var spawner := $Spawner

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
var draw_proximity: bool var draw_proximity: bool
var _boundary_right: float var _boundary_right: float
@ -27,8 +26,8 @@ func _draw() -> void:
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
target.position.x = agent.position.x + _direction.x*_radius target.position.x = agent.position.x + _direction.x * _radius
target.position.y = agent.position.y + _direction.y*_radius target.position.y = agent.position.y + _direction.y * _radius
priority.calculate_steering(_accel) priority.calculate_steering(_accel)
agent._apply_steering(_accel, delta) agent._apply_steering(_accel, delta)
@ -42,7 +41,7 @@ func setup(
boundary_bottom: float, boundary_bottom: float,
_draw_proximity: bool, _draw_proximity: bool,
rng: RandomNumberGenerator rng: RandomNumberGenerator
) -> void: ) -> void:
rng.randomize() rng.randomize()
_direction = Vector2(rng.randf_range(-1, 1), rng.randf_range(-1, 1)).normalized() _direction = Vector2(rng.randf_range(-1, 1), rng.randf_range(-1, 1)).normalized()
@ -75,15 +74,18 @@ func set_random_nonoverlapping_position(others: Array, distance_from_boundary_mi
while tries_max > 0: while tries_max > 0:
tries_max -= 1 tries_max -= 1
global_position.x = rng.randf_range( global_position.x = rng.randf_range(
distance_from_boundary_min, _boundary_right-distance_from_boundary_min distance_from_boundary_min, _boundary_right - distance_from_boundary_min
) )
global_position.y = rng.randf_range( global_position.y = rng.randf_range(
distance_from_boundary_min, _boundary_bottom-distance_from_boundary_min distance_from_boundary_min, _boundary_bottom - distance_from_boundary_min
) )
var done := true var done := true
for i in range(others.size()): for i in range(others.size()):
var other: Node2D = others[i] var other: Node2D = others[i]
if other.global_position.distance_to(position) <= _radius*2 + distance_from_boundary_min: if (
other.global_position.distance_to(position)
<= _radius * 2 + distance_from_boundary_min
):
done = false done = false
if done: if done:
break break

View File

@ -1,6 +1,5 @@
extends Node2D extends Node2D
export var avoider_template: PackedScene export var avoider_template: PackedScene
export var inner_color := Color() export var inner_color := Color()
export var outer_color := Color() export var outer_color := Color()
@ -11,9 +10,9 @@ var boundaries: Vector2
func _ready() -> void: func _ready() -> void:
boundaries = Vector2( boundaries = Vector2(
ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"]
ProjectSettings["display/window/size/height"]) )
var rng: = RandomNumberGenerator.new() var rng := RandomNumberGenerator.new()
var avoiders := [] var avoiders := []
var avoider_agents := [] var avoider_agents := []
for i in range(agent_count): for i in range(agent_count):

View File

@ -1,7 +1,6 @@
class_name DemoPickerUI class_name DemoPickerUI
extends Control extends Control
# warning-ignore:unused_signal # warning-ignore:unused_signal
signal demo_requested signal demo_requested

View File

@ -1,6 +1,5 @@
extends Node extends Node
onready var demo_picker: DemoPickerUI = $DemoPickerUI onready var demo_picker: DemoPickerUI = $DemoPickerUI
onready var demo_player := $DemoPlayer onready var demo_player := $DemoPlayer
onready var button_go_back: Button = $ButtonGoBack onready var button_go_back: Button = $ButtonGoBack

View File

@ -1,11 +1,10 @@
extends Node extends Node
export (int, 0, 359, 2) var angular_speed_max := 120 setget set_angular_speed_max
export(int, 0, 359, 2) var angular_speed_max := 120 setget set_angular_speed_max export (int, 0, 359, 2) var angular_accel_max := 10 setget set_angular_accel_max
export(int, 0, 359, 2) var angular_accel_max := 10 setget set_angular_accel_max export (int, 0, 180, 2) var align_tolerance := 5 setget set_align_tolerance
export(int, 0, 180, 2) var align_tolerance := 5 setget set_align_tolerance export (int, 0, 359, 2) var deceleration_radius := 45 setget set_deceleration_radius
export(int, 0, 359, 2) var deceleration_radius := 45 setget set_deceleration_radius export (float, 0, 1000, 40) var player_speed := 600.0 setget set_player_speed
export(float, 0, 1000, 40) var player_speed := 600.0 setget set_player_speed
onready var player := $Player onready var player := $Player
onready var turret := $Turret onready var turret := $Turret

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
var speed: float var speed: float
onready var agent := GSAIAgentLocation.new() onready var agent := GSAIAgentLocation.new()
@ -15,4 +14,5 @@ func _physics_process(_delta: float) -> void:
func _get_movement() -> Vector2: func _get_movement() -> Vector2:
return Vector2( return Vector2(
Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"),
Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")) Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")
)

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
var face: GSAIFace var face: GSAIFace
var agent := GSAIKinematicBody2DAgent.new(self) var agent := GSAIKinematicBody2DAgent.new(self)
@ -14,7 +13,7 @@ onready var collision_shape := $CollisionShape2D
func _ready() -> void: func _ready() -> void:
var radius = collision_shape.shape.radius var radius = collision_shape.shape.radius
_cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2)) _cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius * 2))
_color = collision_shape.outer_color _color = collision_shape.outer_color

View File

@ -1,9 +1,7 @@
extends Node2D extends Node2D
signal path_established(points) signal path_established(points)
var active_points := [] var active_points := []
var is_drawing := false var is_drawing := false
var distance_threshold := 100.0 var distance_threshold := 100.0

View File

@ -1,12 +1,11 @@
extends Node extends Node
export (float, 0, 2000, 40) var linear_speed_max := 600.0 setget set_linear_speed_max
export(float, 0, 2000, 40) var linear_speed_max := 600.0 setget set_linear_speed_max export (float, 0, 200, 10.0) var linear_acceleration_max := 40.0 setget set_linear_acceleration_max
export(float, 0, 200, 10.0) var linear_acceleration_max := 40.0 setget set_linear_acceleration_max export (float, 0, 100, 0.1) var arrival_tolerance := 10.0 setget set_arrival_tolerance
export(float, 0, 100, 0.1) var arrival_tolerance := 10.0 setget set_arrival_tolerance export (float, 0, 500, 10) var deceleration_radius := 100.0 setget set_deceleration_radius
export(float, 0, 500, 10) var deceleration_radius := 100.0 setget set_deceleration_radius export (float, 0, 5, 0.1) var predict_time := 0.3 setget set_predict_time
export(float, 0, 5, 0.1) var predict_time := 0.3 setget set_predict_time export (float, 0, 200, 10.0) var path_offset := 20.0 setget set_path_offset
export(float, 0, 200, 10.0) var path_offset := 20.0 setget set_path_offset
onready var drawer := $Drawer onready var drawer := $Drawer
onready var follower := $PathFollower onready var follower := $PathFollower

View File

@ -1,17 +1,18 @@
extends KinematicBody2D extends KinematicBody2D
var _velocity := Vector2.ZERO var _velocity := Vector2.ZERO
var _accel := GSAITargetAcceleration.new() var _accel := GSAITargetAcceleration.new()
var _valid := false var _valid := false
var _drag := 0.1 var _drag := 0.1
onready var agent := GSAIKinematicBody2DAgent.new(self) onready var agent := GSAIKinematicBody2DAgent.new(self)
onready var path := GSAIPath.new([ onready var path := GSAIPath.new(
[
Vector3(global_position.x, global_position.y, 0), Vector3(global_position.x, global_position.y, 0),
Vector3(global_position.x, global_position.y, 0) Vector3(global_position.x, global_position.y, 0)
], true) ],
true
)
onready var follow := GSAIFollowPath.new(agent, path, 0, 0) onready var follow := GSAIFollowPath.new(agent, path, 0, 0)
@ -22,7 +23,7 @@ func setup(
speed_max: float, speed_max: float,
decel_radius: float, decel_radius: float,
arrival_tolerance: float arrival_tolerance: float
) -> void: ) -> void:
owner.drawer.connect("path_established", self, "_on_Drawer_path_established") owner.drawer.connect("path_established", self, "_on_Drawer_path_established")
follow.path_offset = path_offset follow.path_offset = path_offset
follow.prediction_time = predict_time follow.prediction_time = predict_time

View File

@ -1,14 +1,13 @@
extends Node extends Node
onready var spawner := $Spawner onready var spawner := $Spawner
export(float, 0, 2000, 40.0) var linear_speed_max := 600.0 setget set_linear_speed_max export (float, 0, 2000, 40.0) var linear_speed_max := 600.0 setget set_linear_speed_max
export(float, 0, 200, 2.0) var linear_accel_max := 40.0 setget set_linear_accel_max export (float, 0, 200, 2.0) var linear_accel_max := 40.0 setget set_linear_accel_max
export(float, 0, 300, 2.0) var proximity_radius := 140.0 setget set_proximity_radius export (float, 0, 300, 2.0) var proximity_radius := 140.0 setget set_proximity_radius
export(float, 0, 10000, 100) var separation_decay_coefficient := 2000.0 setget set_separation_decay_coef export (float, 0, 10000, 100) var separation_decay_coefficient := 2000.0 setget set_separation_decay_coef
export(float, 0, 2, 0.1) var cohesion_strength := 0.1 setget set_cohesion_strength export (float, 0, 2, 0.1) var cohesion_strength := 0.1 setget set_cohesion_strength
export(float, 0, 6, 0.1) var separation_strength := 1.5 setget set_separation_strength export (float, 0, 6, 0.1) var separation_strength := 1.5 setget set_separation_strength
export var show_proximity_radius := true setget set_show_proximity_radius export var show_proximity_radius := true setget set_show_proximity_radius

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
var separation: GSAISeparation var separation: GSAISeparation
var cohesion: GSAICohesion var cohesion: GSAICohesion
var proximity: GSAIRadiusProximity var proximity: GSAIRadiusProximity
@ -22,7 +21,7 @@ func setup(
separation_decay_coefficient: float, separation_decay_coefficient: float,
cohesion_strength: float, cohesion_strength: float,
separation_strength: float separation_strength: float
) -> void: ) -> void:
_color = Color(rand_range(0.5, 1), rand_range(0.25, 1), rand_range(0, 1)) _color = Color(rand_range(0.5, 1), rand_range(0.25, 1), rand_range(0, 1))
collision_shape.inner_color = _color collision_shape.inner_color = _color

View File

@ -1,6 +1,5 @@
extends Node2D extends Node2D
export var member: PackedScene export var member: PackedScene

View File

@ -1,6 +1,5 @@
extends ItemList extends ItemList
signal demo_selected(scene_path) signal demo_selected(scene_path)
var file_paths := PoolStringArray() var file_paths := PoolStringArray()
@ -34,9 +33,11 @@ func sentencify(line: String) -> String:
return line return line
func _find_files(dirpath := "", patterns := PoolStringArray(), is_recursive := false, do_skip_hidden := true) -> PoolStringArray: func _find_files(
var paths: = PoolStringArray() dirpath := "", patterns := PoolStringArray(), is_recursive := false, do_skip_hidden := true
var directory: = Directory.new() ) -> PoolStringArray:
var paths := PoolStringArray()
var directory := Directory.new()
if not directory.dir_exists(dirpath): if not directory.dir_exists(dirpath):
printerr("The directory does not exist: %s" % dirpath) printerr("The directory does not exist: %s" % dirpath)
@ -47,10 +48,10 @@ func _find_files(dirpath := "", patterns := PoolStringArray(), is_recursive := f
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
directory.list_dir_begin(true, do_skip_hidden) directory.list_dir_begin(true, do_skip_hidden)
var file_name: = directory.get_next() var file_name := directory.get_next()
while file_name != "": while file_name != "":
if directory.current_is_dir() and is_recursive: if directory.current_is_dir() and is_recursive:
var subdirectory: = dirpath.plus_file(file_name) var subdirectory := dirpath.plus_file(file_name)
paths.append_array(_find_files(subdirectory, patterns, is_recursive)) paths.append_array(_find_files(subdirectory, patterns, is_recursive))
else: else:
for pattern in patterns: for pattern in patterns:

View File

@ -1,14 +1,12 @@
extends Node2D extends Node2D
# Wraps the ships' positions around the world border. # Wraps the ships' positions around the world border.
var _world_bounds: Vector2 var _world_bounds: Vector2
func _ready() -> void: func _ready() -> void:
_world_bounds = Vector2( _world_bounds = Vector2(
ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"]
ProjectSettings["display/window/size/height"]
) )

View File

@ -1,7 +1,6 @@
extends KinematicBody2D extends KinematicBody2D
# Controls the player ship's movements based on player input. # Controls the player ship's movements based on player input.
export var thruster_strength := 175.0 export var thruster_strength := 175.0
export var side_thruster_strength := 10.0 export var side_thruster_strength := 10.0
export var velocity_max := 300.0 export var velocity_max := 300.0
@ -73,7 +72,7 @@ func _calculate_linear_velocity(
if vertical_movement > 0: if vertical_movement > 0:
actual_strength = strength actual_strength = strength
elif vertical_movement < 0: elif vertical_movement < 0:
actual_strength = -strength/1.5 actual_strength = -strength / 1.5
var velocity := current_velocity + facing_direction * actual_strength * delta var velocity := current_velocity + facing_direction * actual_strength * delta
velocity = velocity.linear_interpolate(Vector2.ZERO, ship_drag_coefficient) velocity = velocity.linear_interpolate(Vector2.ZERO, ship_drag_coefficient)
@ -82,8 +81,10 @@ func _calculate_linear_velocity(
func _get_movement() -> Vector2: func _get_movement() -> Vector2:
return Vector2( Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), return Vector2(
Input.get_action_strength("sf_up") - Input.get_action_strength("sf_down")) Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"),
Input.get_action_strength("sf_up") - Input.get_action_strength("sf_down")
)
func _update_agent() -> void: func _update_agent() -> void:

View File

@ -1,9 +1,8 @@
extends Node extends Node
export (float, 0, 2000, 40) var linear_speed_max := 120.0 setget set_linear_speed_max
export(float, 0, 2000, 40) var linear_speed_max := 120.0 setget set_linear_speed_max export (float, 0, 200, 2) var linear_accel_max := 10.0 setget set_linear_accel_max
export(float, 0, 200, 2) var linear_accel_max := 10.0 setget set_linear_accel_max export (float, 0, 5, 0.1) var predict_time := 1.0 setget set_predict_time
export(float, 0, 5, 0.1) var predict_time := 1.0 setget set_predict_time
onready var pursuer := $BoundaryManager/Pursuer onready var pursuer := $BoundaryManager/Pursuer
onready var seeker := $BoundaryManager/Seeker onready var seeker := $BoundaryManager/Seeker

View File

@ -1,7 +1,6 @@
extends KinematicBody2D extends KinematicBody2D
# Represents a ship that chases after the player. # Represents a ship that chases after the player.
export var use_seek: bool = false export var use_seek: bool = false
var _blend: GSAIBlend var _blend: GSAIBlend
@ -26,23 +25,18 @@ func _physics_process(delta: float) -> void:
_blend.calculate_steering(accel) _blend.calculate_steering(accel)
agent.angular_velocity = clamp( agent.angular_velocity = clamp(
agent.angular_velocity + accel.angular, agent.angular_velocity + accel.angular, -agent.angular_speed_max, agent.angular_speed_max
-agent.angular_speed_max,
agent.angular_speed_max
) )
agent.angular_velocity = lerp(agent.angular_velocity, 0, _angular_drag) agent.angular_velocity = lerp(agent.angular_velocity, 0, _angular_drag)
rotation += agent.angular_velocity * delta rotation += agent.angular_velocity * delta
var linear_velocity := ( var linear_velocity := (
GSAIUtils.to_vector2(agent.linear_velocity) + GSAIUtils.to_vector2(agent.linear_velocity)
(GSAIUtils.angle_to_vector2(rotation) * -agent.linear_acceleration_max) + (GSAIUtils.angle_to_vector2(rotation) * -agent.linear_acceleration_max)
) )
linear_velocity = linear_velocity.clamped(agent.linear_speed_max) linear_velocity = linear_velocity.clamped(agent.linear_speed_max)
linear_velocity = linear_velocity.linear_interpolate( linear_velocity = linear_velocity.linear_interpolate(Vector2.ZERO, _linear_drag_coefficient)
Vector2.ZERO,
_linear_drag_coefficient
)
linear_velocity = move_and_slide(linear_velocity) linear_velocity = move_and_slide(linear_velocity)
agent.linear_velocity = GSAIUtils.to_vector3(linear_velocity) agent.linear_velocity = GSAIUtils.to_vector3(linear_velocity)

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
# Maximum possible linear velocity # Maximum possible linear velocity
export var speed_max := 450.0 export var speed_max := 450.0
# Maximum change in linear velocity # Maximum change in linear velocity
@ -119,9 +118,9 @@ func _physics_process(delta: float) -> void:
# We add the discovered acceleration to our linear velocity. The toolkit does not limit # We add the discovered acceleration to our linear velocity. The toolkit does not limit
# velocity, just acceleration, so we clamp the result ourselves here. # velocity, just acceleration, so we clamp the result ourselves here.
velocity = (velocity + Vector2( velocity = (velocity + Vector2(acceleration.linear.x, acceleration.linear.y)).clamped(
acceleration.linear.x, acceleration.linear.y) agent.linear_speed_max
).clamped(agent.linear_speed_max) )
# This applies drag on the agent's motion, helping it to slow down naturally. # This applies drag on the agent's motion, helping it to slow down naturally.
velocity = velocity.linear_interpolate(Vector2.ZERO, linear_drag) velocity = velocity.linear_interpolate(Vector2.ZERO, linear_drag)
@ -132,9 +131,7 @@ func _physics_process(delta: float) -> void:
# We then do something similar to apply our agent's rotational speed. # We then do something similar to apply our agent's rotational speed.
angular_velocity = clamp( angular_velocity = clamp(
angular_velocity + acceleration.angular, angular_velocity + acceleration.angular, -agent.angular_speed_max, agent.angular_speed_max
-agent.angular_speed_max,
agent.angular_speed_max
) )
# This applies drag on the agent's rotation, helping it slow down naturally. # This applies drag on the agent's rotation, helping it slow down naturally.
angular_velocity = lerp(angular_velocity, 0, angular_drag) angular_velocity = lerp(angular_velocity, 0, angular_drag)

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
export var speed := 1500.0 export var speed := 1500.0
var velocity := Vector2.ZERO var velocity := Vector2.ZERO

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
export var speed_max := 650.0 export var speed_max := 650.0
export var acceleration_max := 70.0 export var acceleration_max := 70.0
export var rotation_speed_max := 240 export var rotation_speed_max := 240
@ -60,8 +59,11 @@ func _unhandled_input(event: InputEvent) -> void:
proxy_target.position.y = mouse_pos.y proxy_target.position.y = mouse_pos.y
elif event is InputEventMouseButton: elif event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed: if event.button_index == BUTTON_LEFT and event.pressed:
var next_bullet: = bullet.instance() var next_bullet := bullet.instance()
next_bullet.global_position = global_position - direction * (agent.bounding_radius-5) next_bullet.global_position = (
global_position
- direction * (agent.bounding_radius - 5)
)
next_bullet.player = self next_bullet.player = self
next_bullet.start(-direction) next_bullet.start(-direction)
bullets.add_child(next_bullet) bullets.add_child(next_bullet)

View File

@ -1,6 +1,5 @@
extends Node2D extends Node2D
const COLOR := Color("8fde5d") const COLOR := Color("8fde5d")
@ -9,27 +8,25 @@ func _ready() -> void:
_on_SceneTree_size_changed() _on_SceneTree_size_changed()
func _draw() -> void: func _draw() -> void:
for b in get_children(): for b in get_children():
var extents: Vector2 = b.get_node("CollisionShape2D").shape.extents var extents: Vector2 = b.get_node("CollisionShape2D").shape.extents
draw_rect(Rect2(b.global_position-extents, extents*2), COLOR) draw_rect(Rect2(b.global_position - extents, extents * 2), COLOR)
func _on_SceneTree_size_changed() -> void: func _on_SceneTree_size_changed() -> void:
var size := Vector2( var size := Vector2(
ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/width"], ProjectSettings["display/window/size/height"]
ProjectSettings["display/window/size/height"]
) )
for b in get_children(): for b in get_children():
var boundary: String = b.name.rsplit("Boundary")[0] var boundary: String = b.name.rsplit("Boundary")[0]
match boundary: match boundary:
"Left": "Left":
b.global_position = Vector2(0, size.y/2) b.global_position = Vector2(0, size.y / 2)
"Right": "Right":
b.global_position = Vector2(size.x, size.y/2) b.global_position = Vector2(size.x, size.y / 2)
"Top": "Top":
b.global_position = Vector2(size.x/2, 0) b.global_position = Vector2(size.x / 2, 0)
"Bottom": "Bottom":
b.global_position = Vector2(size.x/2, size.y) b.global_position = Vector2(size.x / 2, size.y)
update() update()

View File

@ -1,7 +1,6 @@
extends KinematicBody2D extends KinematicBody2D
# Class to control the player in basic left/right up/down movement. # Class to control the player in basic left/right up/down movement.
var speed: float var speed: float
onready var agent := GSAIAgentLocation.new() onready var agent := GSAIAgentLocation.new()
@ -23,4 +22,5 @@ func _physics_process(_delta: float) -> void:
func _get_movement() -> Vector2: func _get_movement() -> Vector2:
return Vector2( return Vector2(
Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"), Input.get_action_strength("sf_right") - Input.get_action_strength("sf_left"),
Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")) Input.get_action_strength("sf_down") - Input.get_action_strength("sf_up")
)

View File

@ -1,13 +1,12 @@
extends Node extends Node
# Access helper class for children to access window boundaries. # Access helper class for children to access window boundaries.
enum Mode { FLEE, SEEK } enum Mode { FLEE, SEEK }
export(Mode) var behavior_mode := Mode.SEEK setget set_behavior_mode export (Mode) var behavior_mode := Mode.SEEK setget set_behavior_mode
export(float, 0, 2000, 40) var linear_speed_max := 200.0 setget set_linear_speed_max export (float, 0, 2000, 40) var linear_speed_max := 200.0 setget set_linear_speed_max
export(float, 0, 500, 0.5) var linear_accel_max := 10.0 setget set_linear_accel_max export (float, 0, 500, 0.5) var linear_accel_max := 10.0 setget set_linear_accel_max
export(float) var player_speed := 600.0 setget set_player_speed export (float) var player_speed := 600.0 setget set_player_speed
var camera_boundaries: Rect2 var camera_boundaries: Rect2

View File

@ -1,6 +1,5 @@
extends KinematicBody2D extends KinematicBody2D
var player_agent: GSAIAgentLocation var player_agent: GSAIAgentLocation
var velocity := Vector2.ZERO var velocity := Vector2.ZERO
var start_speed: float var start_speed: float

View File

@ -1,7 +1,6 @@
extends Node2D extends Node2D
# Holds data to instantiate and configure a number of agent entities. # Holds data to instantiate and configure a number of agent entities.
export (PackedScene) var Entity: PackedScene
export(PackedScene) var Entity: PackedScene export var entity_count := 10
export var entity_count:= 10 export var entity_color := Color.blue
export var entity_color:= Color.blue

View File

@ -1,9 +1,9 @@
tool tool
extends CollisionShape2D extends CollisionShape2D
export(Color) var inner_color := Color() setget set_inner_color export (Color) var inner_color := Color() setget set_inner_color
export(Color) var outer_color := Color() setget set_outer_color export (Color) var outer_color := Color() setget set_outer_color
export(float) var stroke := 0.0 setget set_stroke export (float) var stroke := 0.0 setget set_stroke
func _draw() -> void: func _draw() -> void:

View File

@ -1,13 +1,12 @@
tool tool
extends PanelContainer extends PanelContainer
export (String, MULTILINE) var text_bbcode := "" setget set_text_bbcode
export(String, MULTILINE) var text_bbcode := "" setget set_text_bbcode
onready var rich_text_label: RichTextLabel = $MarginContainer/RichTextLabel onready var rich_text_label: RichTextLabel = $MarginContainer/RichTextLabel
func set_text_bbcode(value: String)-> void: func set_text_bbcode(value: String) -> void:
text_bbcode = value text_bbcode = value
if not rich_text_label: if not rich_text_label:
yield(self, "ready") yield(self, "ready")

View File

@ -1,8 +1,7 @@
tool tool
extends Line2D extends Line2D
export (Color) var inner_color := Color() setget set_inner_color
export(Color) var inner_color := Color() setget set_inner_color
func _draw() -> void: func _draw() -> void:

View File

@ -3,13 +3,11 @@
extends GSAISpecializedAgent extends GSAISpecializedAgent
class_name GSAIKinematicBody2DAgent class_name GSAIKinematicBody2DAgent
# SLIDE uses `move_and_slide` # SLIDE uses `move_and_slide`
# COLLIDE uses `move_and_collide` # COLLIDE uses `move_and_collide`
# POSITION changes the `global_position` directly # POSITION changes the `global_position` directly
enum MovementType { SLIDE, COLLIDE, POSITION } enum MovementType { SLIDE, COLLIDE, POSITION }
# The KinematicBody2D to keep track of # The KinematicBody2D to keep track of
var body: KinematicBody2D setget _set_body var body: KinematicBody2D setget _set_body
@ -57,10 +55,7 @@ func _apply_sliding_steering(accel: Vector3) -> void:
func _apply_collide_steering(accel: Vector3, delta: float) -> void: func _apply_collide_steering(accel: Vector3, delta: float) -> void:
var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max) var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max)
if apply_linear_drag: if apply_linear_drag:
velocity = velocity.linear_interpolate( velocity = velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
Vector3.ZERO,
linear_drag_percentage
)
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
body.move_and_collide(GSAIUtils.to_vector2(velocity) * delta) body.move_and_collide(GSAIUtils.to_vector2(velocity) * delta)
if calculate_velocities: if calculate_velocities:
@ -70,10 +65,7 @@ func _apply_collide_steering(accel: Vector3, delta: float) -> void:
func _apply_position_steering(accel: Vector3, delta: float) -> void: func _apply_position_steering(accel: Vector3, delta: float) -> void:
var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max) var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max)
if apply_linear_drag: if apply_linear_drag:
velocity = velocity.linear_interpolate( velocity = velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
Vector3.ZERO,
linear_drag_percentage
)
body.global_position += GSAIUtils.to_vector2(velocity) * delta body.global_position += GSAIUtils.to_vector2(velocity) * delta
if calculate_velocities: if calculate_velocities:
linear_velocity = velocity linear_velocity = velocity
@ -110,27 +102,19 @@ func _on_SceneTree_physics_frame() -> void:
_applied_steering = false _applied_steering = false
else: else:
linear_velocity = GSAIUtils.clampedv3( linear_velocity = GSAIUtils.clampedv3(
GSAIUtils.to_vector3(_last_position - current_position), GSAIUtils.to_vector3(_last_position - current_position), linear_speed_max
linear_speed_max
) )
if apply_linear_drag: if apply_linear_drag:
linear_velocity = linear_velocity.linear_interpolate( linear_velocity = linear_velocity.linear_interpolate(
Vector3.ZERO, Vector3.ZERO, linear_drag_percentage
linear_drag_percentage
) )
angular_velocity = clamp( angular_velocity = clamp(
_last_orientation - current_orientation, _last_orientation - current_orientation, -angular_speed_max, angular_speed_max
-angular_speed_max,
angular_speed_max
) )
if apply_angular_drag: if apply_angular_drag:
angular_velocity = lerp( angular_velocity = lerp(angular_velocity, 0, angular_drag_percentage)
angular_velocity,
0,
angular_drag_percentage
)
_last_position = current_position _last_position = current_position
_last_orientation = current_orientation _last_orientation = current_orientation

View File

@ -8,7 +8,6 @@ class_name GSAIKinematicBody3DAgent
# POSITION changes the global_position directly # POSITION changes the global_position directly
enum MovementType { SLIDE, COLLIDE, POSITION } enum MovementType { SLIDE, COLLIDE, POSITION }
# The KinematicBody to keep track of # The KinematicBody to keep track of
var body: KinematicBody setget _set_body var body: KinematicBody setget _set_body
@ -56,10 +55,7 @@ func _apply_sliding_steering(accel: Vector3) -> void:
func _apply_collide_steering(accel: Vector3, delta: float) -> void: func _apply_collide_steering(accel: Vector3, delta: float) -> void:
var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max) var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max)
if apply_linear_drag: if apply_linear_drag:
velocity = velocity.linear_interpolate( velocity = velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
Vector3.ZERO,
linear_drag_percentage
)
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
body.move_and_collide(velocity * delta) body.move_and_collide(velocity * delta)
if calculate_velocities: if calculate_velocities:
@ -69,10 +65,7 @@ func _apply_collide_steering(accel: Vector3, delta: float) -> void:
func _apply_position_steering(accel: Vector3, delta: float) -> void: func _apply_position_steering(accel: Vector3, delta: float) -> void:
var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max) var velocity := GSAIUtils.clampedv3(linear_velocity + accel, linear_speed_max)
if apply_linear_drag: if apply_linear_drag:
velocity = velocity.linear_interpolate( velocity = velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
Vector3.ZERO,
linear_drag_percentage
)
body.global_position += velocity * delta body.global_position += velocity * delta
if calculate_velocities: if calculate_velocities:
linear_velocity = velocity linear_velocity = velocity
@ -109,27 +102,19 @@ func _on_SceneTree_physics_frame() -> void:
_applied_steering = false _applied_steering = false
else: else:
linear_velocity = GSAIUtils.clampedv3( linear_velocity = GSAIUtils.clampedv3(
_last_position - current_position, _last_position - current_position, linear_speed_max
linear_speed_max
) )
if apply_linear_drag: if apply_linear_drag:
linear_velocity = linear_velocity.linear_interpolate( linear_velocity = linear_velocity.linear_interpolate(
Vector3.ZERO, Vector3.ZERO, linear_drag_percentage
linear_drag_percentage
) )
angular_velocity = clamp( angular_velocity = clamp(
_last_orientation - current_orientation, _last_orientation - current_orientation, -angular_speed_max, angular_speed_max
-angular_speed_max,
angular_speed_max
) )
if apply_angular_drag: if apply_angular_drag:
angular_velocity = lerp( angular_velocity = lerp(angular_velocity, 0, angular_drag_percentage)
angular_velocity,
0,
angular_drag_percentage
)
_last_position = current_position _last_position = current_position
_last_orientation = current_orientation _last_orientation = current_orientation

View File

@ -3,7 +3,6 @@
extends GSAISpecializedAgent extends GSAISpecializedAgent
class_name GSAIRigidBody2DAgent class_name GSAIRigidBody2DAgent
# The RigidBody2D to keep track of # The RigidBody2D to keep track of
var body: RigidBody2D setget _set_body var body: RigidBody2D setget _set_body

View File

@ -3,7 +3,6 @@
extends GSAISpecializedAgent extends GSAISpecializedAgent
class_name GSAIRigidBody3DAgent class_name GSAIRigidBody3DAgent
# The RigidBody to keep track of # The RigidBody to keep track of
var body: RigidBody setget _set_body var body: RigidBody setget _set_body
@ -19,7 +18,6 @@ func _init(_body: RigidBody) -> void:
self.body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") self.body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame")
# Moves the agent's `body` by target `acceleration`. # Moves the agent's `body` by target `acceleration`.
# tags: virtual # tags: virtual
func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void: func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> void:

View File

@ -4,7 +4,6 @@
extends GSAISteeringAgent extends GSAISteeringAgent
class_name GSAISpecializedAgent class_name GSAISpecializedAgent
# If `true`, calculates linear and angular velocities based on the previous # If `true`, calculates linear and angular velocities based on the previous
# frame. When `false`, the user must keep those values updated. # frame. When `false`, the user must keep those values updated.
var calculate_velocities := true var calculate_velocities := true

View File

@ -3,7 +3,6 @@
class_name GSAIArrive class_name GSAIArrive
extends GSAISteeringBehavior extends GSAISteeringBehavior
# Target agent to arrive to. # Target agent to arrive to.
var target: GSAIAgentLocation var target: GSAIAgentLocation
# Distance from the target for the agent to be considered successfully # Distance from the target for the agent to be considered successfully
@ -31,9 +30,9 @@ func _arrive(acceleration: GSAITargetAcceleration, target_position: Vector3) ->
if distance <= deceleration_radius: if distance <= deceleration_radius:
desired_speed *= distance / deceleration_radius desired_speed *= distance / deceleration_radius
var desired_velocity := to_target * desired_speed/distance var desired_velocity := to_target * desired_speed / distance
desired_velocity = (desired_velocity - agent.linear_velocity) * 1.0 / time_to_reach desired_velocity = ((desired_velocity - agent.linear_velocity) * 1.0 / time_to_reach)
acceleration.linear = GSAIUtils.clampedv3(desired_velocity, agent.linear_acceleration_max) acceleration.linear = GSAIUtils.clampedv3(desired_velocity, agent.linear_acceleration_max)
acceleration.angular = 0 acceleration.angular = 0

View File

@ -3,7 +3,6 @@
class_name GSAIAvoidCollisions class_name GSAIAvoidCollisions
extends GSAIGroupBehavior extends GSAIGroupBehavior
var _first_neighbor: GSAISteeringAgent var _first_neighbor: GSAISteeringAgent
var _shortest_time: float var _shortest_time: float
var _first_minimum_separation: float var _first_minimum_separation: float
@ -27,14 +26,18 @@ func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
if neighbor_count == 0 or not _first_neighbor: if neighbor_count == 0 or not _first_neighbor:
acceleration.set_zero() acceleration.set_zero()
else: else:
if( if (
_first_minimum_separation <= 0 or _first_minimum_separation <= 0
_first_distance < agent.bounding_radius + _first_neighbor.bounding_radius): or _first_distance < agent.bounding_radius + _first_neighbor.bounding_radius
):
acceleration.linear = _first_neighbor.position - agent.position acceleration.linear = _first_neighbor.position - agent.position
else: else:
acceleration.linear = _first_relative_position + (_first_relative_velocity * _shortest_time) acceleration.linear = (
_first_relative_position
+ (_first_relative_velocity * _shortest_time)
)
acceleration.linear = acceleration.linear.normalized() * -agent.linear_acceleration_max acceleration.linear = (acceleration.linear.normalized() * -agent.linear_acceleration_max)
acceleration.angular = 0 acceleration.angular = 0
@ -55,7 +58,10 @@ func _report_neighbor(neighbor: GSAISteeringAgent) -> bool:
return false return false
else: else:
var distance = relative_position.length() var distance = relative_position.length()
var minimum_separation: float = distance - sqrt(relative_speed_squared) * time_to_collision var minimum_separation: float = (
distance
- sqrt(relative_speed_squared) * time_to_collision
)
if minimum_separation > agent.bounding_radius + neighbor.bounding_radius: if minimum_separation > agent.bounding_radius + neighbor.bounding_radius:
return false return false
else: else:

View File

@ -9,7 +9,6 @@
class_name GSAIBlend class_name GSAIBlend
extends GSAISteeringBehavior extends GSAISteeringBehavior
var _behaviors := [] var _behaviors := []
var _accel := GSAITargetAcceleration.new() var _accel := GSAITargetAcceleration.new()
@ -44,7 +43,5 @@ func _calculate_steering(blended_accel: GSAITargetAcceleration) -> void:
blended_accel.linear = GSAIUtils.clampedv3(blended_accel.linear, agent.linear_acceleration_max) blended_accel.linear = GSAIUtils.clampedv3(blended_accel.linear, agent.linear_acceleration_max)
blended_accel.angular = clamp( blended_accel.angular = clamp(
blended_accel.angular, blended_accel.angular, -agent.angular_acceleration_max, agent.angular_acceleration_max
-agent.angular_acceleration_max,
agent.angular_acceleration_max
) )

View File

@ -3,7 +3,6 @@
class_name GSAICohesion class_name GSAICohesion
extends GSAIGroupBehavior extends GSAIGroupBehavior
var _center_of_mass: Vector3 var _center_of_mass: Vector3
@ -17,7 +16,10 @@ func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
var neighbor_count = proximity._find_neighbors(_callback) var neighbor_count = proximity._find_neighbors(_callback)
if neighbor_count > 0: if neighbor_count > 0:
_center_of_mass *= 1.0 / neighbor_count _center_of_mass *= 1.0 / neighbor_count
acceleration.linear = (_center_of_mass - agent.position).normalized() * agent.linear_acceleration_max acceleration.linear = (
(_center_of_mass - agent.position).normalized()
* agent.linear_acceleration_max
)
# Callback for the proximity to call when finding neighbors. Adds `neighbor`'s position # Callback for the proximity to call when finding neighbors. Adds `neighbor`'s position

View File

@ -4,10 +4,9 @@ class_name GSAIEvade
extends GSAIPursue extends GSAIPursue
func _init( func _init(agent: GSAISteeringAgent, target: GSAISteeringAgent, predict_time_max := 1.0).(
agent: GSAISteeringAgent, agent, target, predict_time_max
target: GSAISteeringAgent, ):
predict_time_max := 1.0).(agent, target, predict_time_max):
pass pass

View File

@ -4,7 +4,9 @@ class_name GSAIFace
extends GSAIMatchOrientation extends GSAIMatchOrientation
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation, use_z := false).(agent, target, use_z) -> void: func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation, use_z := false).(
agent, target, use_z
) -> void:
pass pass
@ -15,7 +17,8 @@ func _face(acceleration: GSAITargetAcceleration, target_position: Vector3) -> vo
if distance_squared < agent.zero_linear_speed_threshold: if distance_squared < agent.zero_linear_speed_threshold:
acceleration.set_zero() acceleration.set_zero()
else: else:
var orientation = (GSAIUtils.vector3_to_angle(to_target) var orientation = (
GSAIUtils.vector3_to_angle(to_target)
if use_z if use_z
else GSAIUtils.vector2_to_angle(GSAIUtils.to_vector2(to_target)) else GSAIUtils.vector2_to_angle(GSAIUtils.to_vector2(to_target))
) )

View File

@ -9,5 +9,7 @@ func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent, target)
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
acceleration.linear = ( acceleration.linear = (
(agent.position - target.position).normalized() * agent.linear_acceleration_max) (agent.position - target.position).normalized()
* agent.linear_acceleration_max
)
acceleration.angular = 0 acceleration.angular = 0

View File

@ -2,7 +2,6 @@
class_name GSAIFollowPath class_name GSAIFollowPath
extends GSAIArrive extends GSAIArrive
# The path to follow and travel along. # The path to follow and travel along.
var path: GSAIPath var path: GSAIPath
# The distance along the path to generate the next target position. # The distance along the path to generate the next target position.
@ -15,11 +14,9 @@ var is_arrive_enabled := true
var prediction_time := 0.0 var prediction_time := 0.0
func _init( func _init(agent: GSAISteeringAgent, _path: GSAIPath, _path_offset := 0.0, _prediction_time := 0.0).(
agent: GSAISteeringAgent, agent, null
_path: GSAIPath, ) -> void:
_path_offset := 0.0,
_prediction_time := 0.0).(agent, null) -> void:
self.path = _path self.path = _path
self.path_offset = _path_offset self.path_offset = _path_offset
self.prediction_time = _prediction_time self.prediction_time = _prediction_time
@ -27,8 +24,10 @@ func _init(
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
var location := ( var location := (
agent.position if prediction_time == 0 agent.position
else agent.position + (agent.linear_velocity * prediction_time)) if prediction_time == 0
else agent.position + (agent.linear_velocity * prediction_time)
)
var distance := path.calculate_distance(location) var distance := path.calculate_distance(location)
var target_distance := distance + path_offset var target_distance := distance + path_offset

View File

@ -12,7 +12,8 @@ func _calculate_steering(accel: GSAITargetAcceleration) -> void:
if agent.linear_velocity.length_squared() < agent.zero_linear_speed_threshold: if agent.linear_velocity.length_squared() < agent.zero_linear_speed_threshold:
accel.set_zero() accel.set_zero()
else: else:
var orientation := (GSAIUtils.vector3_to_angle(agent.linear_velocity) var orientation := (
GSAIUtils.vector3_to_angle(agent.linear_velocity)
if use_z if use_z
else GSAIUtils.vector2_to_angle(GSAIUtils.to_vector2(agent.linear_velocity)) else GSAIUtils.vector2_to_angle(GSAIUtils.to_vector2(agent.linear_velocity))
) )

View File

@ -4,7 +4,6 @@
class_name GSAIMatchOrientation class_name GSAIMatchOrientation
extends GSAISteeringBehavior extends GSAISteeringBehavior
# 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: GSAIAgentLocation var target: GSAIAgentLocation
# The amount of distance in radians for the behavior to consider itself close # The amount of distance in radians for the behavior to consider itself close
@ -39,11 +38,11 @@ func _match_orientation(acceleration: GSAITargetAcceleration, desired_orientatio
desired_rotation *= rotation / rotation_size desired_rotation *= rotation / rotation_size
acceleration.angular = (desired_rotation - agent.angular_velocity) / time_to_reach acceleration.angular = ((desired_rotation - agent.angular_velocity) / time_to_reach)
var limited_acceleration := abs(acceleration.angular) var limited_acceleration := abs(acceleration.angular)
if limited_acceleration > agent.angular_acceleration_max: if limited_acceleration > agent.angular_acceleration_max:
acceleration.angular *= agent.angular_acceleration_max / limited_acceleration acceleration.angular *= (agent.angular_acceleration_max / limited_acceleration)
acceleration.linear = Vector3.ZERO acceleration.linear = Vector3.ZERO

View File

@ -3,7 +3,6 @@
class_name GSAIPriority class_name GSAIPriority
extends GSAISteeringBehavior extends GSAISteeringBehavior
var _behaviors := [] var _behaviors := []
# The index of the last behavior the container prioritized. # The index of the last behavior the container prioritized.

View File

@ -3,7 +3,6 @@
class_name GSAIPursue class_name GSAIPursue
extends GSAISteeringBehavior extends GSAISteeringBehavior
# The target agent that the behavior is trying to intercept. # The target agent that the behavior is trying to intercept.
var target: GSAISteeringAgent var target: GSAISteeringAgent
# The maximum amount of time in the future the behavior predicts the target's # The maximum amount of time in the future the behavior predicts the target's
@ -11,10 +10,7 @@ var target: GSAISteeringAgent
var predict_time_max: float var predict_time_max: float
func _init( func _init(agent: GSAISteeringAgent, _target: GSAISteeringAgent, _predict_time_max := 1.0).(agent) -> void:
agent: GSAISteeringAgent,
_target: GSAISteeringAgent,
_predict_time_max := 1.0).(agent) -> void:
self.target = _target self.target = _target
self.predict_time_max = _predict_time_max self.predict_time_max = _predict_time_max
@ -31,8 +27,7 @@ func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
if predict_time_squared < predict_time_max * predict_time_max: if predict_time_squared < predict_time_max * predict_time_max:
predict_time = sqrt(predict_time_squared) predict_time = sqrt(predict_time_squared)
acceleration.linear = (( acceleration.linear = ((target_position + (target.linear_velocity * predict_time)) - agent.position).normalized()
target_position + (target.linear_velocity * predict_time))-agent.position).normalized()
acceleration.linear *= _get_modified_acceleration() acceleration.linear *= _get_modified_acceleration()
acceleration.angular = 0 acceleration.angular = 0

View File

@ -3,7 +3,6 @@
class_name GSAISeek class_name GSAISeek
extends GSAISteeringBehavior extends GSAISteeringBehavior
# The target that the behavior aims to move the agent to. # The target that the behavior aims to move the agent to.
var target: GSAIAgentLocation var target: GSAIAgentLocation
@ -14,5 +13,7 @@ func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
acceleration.linear = ( acceleration.linear = (
(target.position - agent.position).normalized() * agent.linear_acceleration_max) (target.position - agent.position).normalized()
* agent.linear_acceleration_max
)
acceleration.angular = 0 acceleration.angular = 0

View File

@ -7,7 +7,6 @@
class_name GSAISeparation class_name GSAISeparation
extends GSAIGroupBehavior extends GSAIGroupBehavior
# 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

View File

@ -1,7 +1,6 @@
# Represents an agent with only a location and an orientation. # Represents an agent with only a location and an orientation.
class_name GSAIAgentLocation class_name GSAIAgentLocation
# The agent's position in space. # The agent's position in space.
var position := Vector3.ZERO var position := Vector3.ZERO
# The agent's orientation on its Y axis rotation. # The agent's orientation on its Y axis rotation.

View File

@ -2,7 +2,6 @@
class_name GSAIGroupBehavior class_name GSAIGroupBehavior
extends GSAISteeringBehavior extends GSAISteeringBehavior
# Container to find neighbors of the agent and calculate group behavior. # Container to find neighbors of the agent and calculate group behavior.
var proximity: GSAIProximity var proximity: GSAIProximity

View File

@ -3,7 +3,6 @@
class_name GSAIPath class_name GSAIPath
extends Reference extends Reference
# If `false`, the path loops. # If `false`, the path loops.
var is_open: bool var is_open: bool
# Total length of the path. # Total length of the path.
@ -56,9 +55,7 @@ func calculate_distance(agent_current_position: Vector3) -> float:
for i in range(_segments.size()): for i in range(_segments.size()):
var segment: GSAISegment = _segments[i] var segment: GSAISegment = _segments[i]
var distance_squared := _calculate_point_segment_distance_squared( var distance_squared := _calculate_point_segment_distance_squared(
segment.begin, segment.begin, segment.end, agent_current_position
segment.end,
agent_current_position
) )
if distance_squared < smallest_distance_squared: if distance_squared < smallest_distance_squared:
@ -67,8 +64,9 @@ func calculate_distance(agent_current_position: Vector3) -> float:
nearest_segment = segment nearest_segment = segment
var length_on_path := ( var length_on_path := (
nearest_segment.cumulative_length - nearest_segment.cumulative_length
_nearest_point_on_path.distance_to(nearest_segment.end)) - _nearest_point_on_path.distance_to(nearest_segment.end)
)
return length_on_path return length_on_path
@ -96,8 +94,9 @@ func calculate_target_position(target_distance: float) -> Vector3:
var distance := desired_segment.cumulative_length - target_distance var distance := desired_segment.cumulative_length - target_distance
return ( return (
(desired_segment.begin - desired_segment.end) * ((desired_segment.begin - desired_segment.end) * (distance / desired_segment.length))
(distance / desired_segment.length) + desired_segment.end) + desired_segment.end
)
# Returns the position of the first point on the path. # Returns the position of the first point on the path.
@ -127,7 +126,6 @@ class GSAISegment:
var length: float var length: float
var cumulative_length: float var cumulative_length: float
func _init(_begin: Vector3, _end: Vector3) -> void: func _init(_begin: Vector3, _end: Vector3) -> void:
self.begin = _begin self.begin = _begin
self.end = _end self.end = _end

View File

@ -5,7 +5,6 @@
extends GSAIAgentLocation extends GSAIAgentLocation
class_name GSAISteeringAgent class_name GSAISteeringAgent
# The amount of velocity to be considered effectively not moving. # The amount of velocity to be considered effectively not moving.
var zero_linear_speed_threshold := 0.01 var zero_linear_speed_threshold := 0.01
# The maximum speed at which the agent can move. # The maximum speed at which the agent can move.

View File

@ -7,7 +7,6 @@
# Individual steering behaviors encapsulate the steering logic. # Individual steering behaviors encapsulate the steering logic.
class_name GSAISteeringBehavior class_name GSAISteeringBehavior
# If `false`, all calculations return zero amounts of acceleration. # If `false`, all calculations return zero amounts of acceleration.
var is_enabled := true var is_enabled := true
# The AI agent on which the steering behavior bases its calculations. # The AI agent on which the steering behavior bases its calculations.

View File

@ -2,7 +2,6 @@
# system. # system.
class_name GSAITargetAcceleration class_name GSAITargetAcceleration
# Linear acceleration # Linear acceleration
var linear := Vector3.ZERO var linear := Vector3.ZERO
# Angular acceleration # Angular acceleration

View File

@ -1,7 +1,6 @@
# Math and vector utility functions. # Math and vector utility functions.
class_name GSAIUtils class_name GSAIUtils
# Returns the `vector` with its length capped to `limit`. # Returns the `vector` with its length capped to `limit`.
static func clampedv3(vector: Vector3, limit: float) -> Vector3: static func clampedv3(vector: Vector3, limit: float) -> Vector3:
var length_squared := vector.length_squared() var length_squared := vector.length_squared()
@ -10,7 +9,6 @@ static func clampedv3(vector: Vector3, limit: float) -> Vector3:
vector *= sqrt(limit_squared / length_squared) vector *= sqrt(limit_squared / length_squared)
return vector return vector
# Returns an angle in radians between the positive X axis and the `vector`. # Returns an angle in radians between the positive X axis and the `vector`.
# #
# This assumes orientation for 3D agents that are upright and rotate # This assumes orientation for 3D agents that are upright and rotate
@ -18,12 +16,10 @@ static func clampedv3(vector: Vector3, limit: float) -> Vector3:
static func vector3_to_angle(vector: Vector3) -> float: static func vector3_to_angle(vector: Vector3) -> float:
return atan2(vector.x, vector.z) return atan2(vector.x, vector.z)
# Returns an angle in radians between the positive X axis and the `vector`. # Returns an angle in radians between the positive X axis and the `vector`.
static func vector2_to_angle(vector: Vector2) -> float: static func vector2_to_angle(vector: Vector2) -> float:
return atan2(vector.x, -vector.y) return atan2(vector.x, -vector.y)
# Returns a directional vector from the given orientation angle. # Returns a directional vector from the given orientation angle.
# #
# This assumes orientation for 2D agents or 3D agents that are upright and # This assumes orientation for 2D agents or 3D agents that are upright and
@ -31,12 +27,10 @@ static func vector2_to_angle(vector: Vector2) -> float:
static func angle_to_vector2(angle: float) -> Vector2: static func angle_to_vector2(angle: float) -> Vector2:
return Vector2(sin(-angle), cos(angle)) return Vector2(sin(-angle), cos(angle))
# Returns a vector2 with `vector`'s x and y components. # Returns a vector2 with `vector`'s x and y components.
static func to_vector2(vector: Vector3) -> Vector2: static func to_vector2(vector: Vector3) -> Vector2:
return Vector2(vector.x, vector.y) return Vector2(vector.x, vector.y)
# Returns a vector3 with `vector`'s x and y components and 0 in z. # Returns a vector3 with `vector`'s x and y components and 0 in z.
static func to_vector3(vector: Vector2) -> Vector3: static func to_vector3(vector: Vector2) -> Vector3:
return Vector3(vector.x, vector.y, 0) return Vector3(vector.x, vector.y, 0)

View File

@ -2,7 +2,6 @@
extends Reference extends Reference
class_name GSAIProximity class_name GSAIProximity
# The owning agent whose neighbors are found in the group # The owning agent whose neighbors are found in the group
var agent: GSAISteeringAgent var agent: GSAISteeringAgent
# The agents who are part of this group and could be potential neighbors # The agents who are part of this group and could be potential neighbors

View File

@ -3,7 +3,6 @@
extends GSAIProximity extends GSAIProximity
class_name GSAIRadiusProximity class_name GSAIRadiusProximity
# The radius around the owning agent to find neighbors in # The radius around the owning agent to find neighbors in
var radius := 0.0 var radius := 0.0