mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-12-24 05:37:15 +01:00
Use GSAI as a class prefix instead of GST
GSAI for Godot Steering AI
This commit is contained in:
parent
7241bc754b
commit
7eb91a6165
30
README.md
30
README.md
@ -74,32 +74,32 @@ var linear_drag := 0.1
|
|||||||
var angular_drag := 0.1
|
var angular_drag := 0.1
|
||||||
|
|
||||||
# Holds the linear and angular components calculated by our steering behaviors.
|
# Holds the linear and angular components calculated by our steering behaviors.
|
||||||
var acceleration := GSTTargetAcceleration.new()
|
var acceleration := GSAITargetAcceleration.new()
|
||||||
|
|
||||||
onready var current_health := health_max
|
onready var current_health := health_max
|
||||||
|
|
||||||
# GSTSteeringAgent holds our agent's position, orientation, maximum speed and acceleration.
|
# GSAISteeringAgent holds our agent's position, orientation, maximum speed and acceleration.
|
||||||
onready var agent := GSTSteeringAgent.new()
|
onready var agent := GSAISteeringAgent.new()
|
||||||
|
|
||||||
onready var player: Node = get_tree().get_nodes_in_group("Player")[0]
|
onready var player: Node = get_tree().get_nodes_in_group("Player")[0]
|
||||||
# This assumes that our player class will keep its own agent updated.
|
# This assumes that our player class will keep its own agent updated.
|
||||||
onready var player_agent: GSTSteeringAgent = player.agent
|
onready var player_agent: GSAISteeringAgent = player.agent
|
||||||
|
|
||||||
# Proximities represent an area with which an agent can identify where neighbors in its relevant
|
# Proximities represent an area with which an agent can identify where neighbors in its relevant
|
||||||
# group are. In our case, the group will feature the player, which will be used to avoid a
|
# group are. In our case, the group will feature the player, which will be used to avoid a
|
||||||
# collision with them. We use a radius proximity so the player is only relevant inside 100 pixels
|
# collision with them. We use a radius proximity so the player is only relevant inside 100 pixels
|
||||||
onready var proximity := GSTRadiusProximity.new(agent, [player_agent], 100).
|
onready var proximity := GSAIRadiusProximity.new(agent, [player_agent], 100).
|
||||||
|
|
||||||
# GSTBlend combines behaviors together, calculating all of their acceleration together and adding
|
# GSAIBlend combines behaviors together, calculating all of their acceleration together and adding
|
||||||
# them together, multiplied by a strength. We will have one for fleeing, and one for pursuing,
|
# them together, multiplied by a strength. We will have one for fleeing, and one for pursuing,
|
||||||
# toggling them depending on the agent's health. Since we want the agent to rotate AND move, then
|
# toggling them depending on the agent's health. Since we want the agent to rotate AND move, then
|
||||||
# we aim to blend them together.
|
# we aim to blend them together.
|
||||||
onready var flee_blend := GSTBlend.new(agent)
|
onready var flee_blend := GSAIBlend.new(agent)
|
||||||
onready var pursue_blend := GSTBlend.new(agent)
|
onready var pursue_blend := GSAIBlend.new(agent)
|
||||||
|
|
||||||
# GSTPriority will be the main steering behavior we use. It holds sub-behaviors and will pick the
|
# GSAIPriority will be the main steering behavior we use. It holds sub-behaviors and will pick the
|
||||||
# first one that returns non-zero acceleration, ignoring any afterwards.
|
# first one that returns non-zero acceleration, ignoring any afterwards.
|
||||||
onready var priority := GSTPriority.new(agent)
|
onready var priority := GSAIPriority.new(agent)
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@ -114,20 +114,20 @@ func _ready() -> void:
|
|||||||
# ---------- Configuration for our behaviors ----------
|
# ---------- Configuration for our behaviors ----------
|
||||||
# Pursue will happen while the player is in good health. It produces acceleration that takes
|
# Pursue will happen while the player is in good health. It produces acceleration that takes
|
||||||
# the agent on an intercept course with the target, predicting its position in the future.
|
# the agent on an intercept course with the target, predicting its position in the future.
|
||||||
var pursue := GSTPursue.new(agent, player_agent)
|
var pursue := GSAIPursue.new(agent, player_agent)
|
||||||
pursue.predict_time_max = 1.5
|
pursue.predict_time_max = 1.5
|
||||||
|
|
||||||
# Flee will happen while the agent is in bad health, so will start disabled. It produces
|
# Flee will happen while the agent is in bad health, so will start disabled. It produces
|
||||||
# acceleration that takes the agent directly away from the target with no prediction.
|
# acceleration that takes the agent directly away from the target with no prediction.
|
||||||
var flee := GSTFlee.new(agent, player_agent)
|
var flee := GSAIFlee.new(agent, player_agent)
|
||||||
|
|
||||||
# AvoidCollision tries to keep the agent from running into any of the neighbors found in its
|
# AvoidCollision tries to keep the agent from running into any of the neighbors found in its
|
||||||
# proximity group. In our case, this will be the player if they are close enough.
|
# proximity group. In our case, this will be the player if they are close enough.
|
||||||
var avoid := GSTAvoidCollisions.new(agent, proximity)
|
var avoid := GSAIAvoidCollisions.new(agent, proximity)
|
||||||
|
|
||||||
# Face turns the agent to keep looking towards its target. It will be enabled while the agent
|
# Face turns the agent to keep looking towards its target. It will be enabled while the agent
|
||||||
# is not fleeing due to low health. It tries to arrive 'on alignment' with 0 remaining velocity.
|
# is not fleeing due to low health. It tries to arrive 'on alignment' with 0 remaining velocity.
|
||||||
var face := GSTFace.new(agent, player_agent)
|
var face := GSAIFace.new(agent, player_agent)
|
||||||
|
|
||||||
# We use deg2rad because the math in the toolkit assumes radians.
|
# We use deg2rad because the math in the toolkit assumes radians.
|
||||||
# How close for the agent to be 'aligned', if not exact.
|
# How close for the agent to be 'aligned', if not exact.
|
||||||
@ -137,7 +137,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
# LookWhereYouGo turns the agent to keep looking towards its direction of travel. It will only
|
# LookWhereYouGo turns the agent to keep looking towards its direction of travel. It will only
|
||||||
# be enabled while the agent is at low health.
|
# be enabled while the agent is at low health.
|
||||||
var look := GSTLookWhereYouGo.new(agent)
|
var look := GSAILookWhereYouGo.new(agent)
|
||||||
# How close for the agent to be 'aligned', if not exact.
|
# How close for the agent to be 'aligned', if not exact.
|
||||||
look.alignment_tolerance = deg2rad(5)
|
look.alignment_tolerance = deg2rad(5)
|
||||||
# When to start slowing down.
|
# When to start slowing down.
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
var agent := GSTKinematicBody2DAgent.new(self)
|
var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
var target := GSTAgentLocation.new()
|
var target := GSAIAgentLocation.new()
|
||||||
var arrive := GSTArrive.new(agent, target)
|
var arrive := GSAIArrive.new(agent, target)
|
||||||
var _accel := GSTTargetAcceleration.new()
|
var _accel := GSAITargetAcceleration.new()
|
||||||
|
|
||||||
var _velocity := Vector2()
|
var _velocity := Vector2()
|
||||||
var _drag := 0.1
|
var _drag := 0.1
|
||||||
|
@ -15,6 +15,6 @@ func _ready() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
var target_position := GSTUtils.to_vector2(arriver.target.position)
|
var target_position := GSAIUtils.to_vector2(arriver.target.position)
|
||||||
draw_circle(target_position, owner.deceleration_radius, COLORS.deceleration_radius)
|
draw_circle(target_position, owner.deceleration_radius, COLORS.deceleration_radius)
|
||||||
draw_circle(target_position, owner.arrival_tolerance, COLORS.arrival_tolerance)
|
draw_circle(target_position, owner.arrival_tolerance, COLORS.arrival_tolerance)
|
||||||
|
@ -6,19 +6,19 @@ var draw_proximity: bool
|
|||||||
var _boundary_right: float
|
var _boundary_right: float
|
||||||
var _boundary_bottom: float
|
var _boundary_bottom: float
|
||||||
var _radius: float
|
var _radius: float
|
||||||
var _accel := GSTTargetAcceleration.new()
|
var _accel := GSAITargetAcceleration.new()
|
||||||
var _velocity := Vector2.ZERO
|
var _velocity := Vector2.ZERO
|
||||||
var _direction := Vector2()
|
var _direction := Vector2()
|
||||||
var _drag := 0.1
|
var _drag := 0.1
|
||||||
var _color := Color(0.4, 1.0, 0.89, 0.3)
|
var _color := Color(0.4, 1.0, 0.89, 0.3)
|
||||||
|
|
||||||
onready var collision := $CollisionShape2D
|
onready var collision := $CollisionShape2D
|
||||||
onready var agent := GSTKinematicBody2DAgent.new(self)
|
onready var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
onready var proximity := GSTRadiusProximity.new(agent, [], 140)
|
onready var proximity := GSAIRadiusProximity.new(agent, [], 140)
|
||||||
onready var avoid := GSTAvoidCollisions.new(agent, proximity)
|
onready var avoid := GSAIAvoidCollisions.new(agent, proximity)
|
||||||
onready var target := GSTAgentLocation.new()
|
onready var target := GSAIAgentLocation.new()
|
||||||
onready var seek := GSTSeek.new(agent, target)
|
onready var seek := GSAISeek.new(agent, target)
|
||||||
onready var priority := GSTPriority.new(agent, 0.0001)
|
onready var priority := GSAIPriority.new(agent, 0.0001)
|
||||||
|
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
|
@ -3,7 +3,7 @@ extends KinematicBody2D
|
|||||||
|
|
||||||
var speed: float
|
var speed: float
|
||||||
|
|
||||||
onready var agent := GSTAgentLocation.new()
|
onready var agent := GSAIAgentLocation.new()
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
var face: GSTFace
|
var face: GSAIFace
|
||||||
var agent := GSTKinematicBody2DAgent.new(self)
|
var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
|
|
||||||
var _accel := GSTTargetAcceleration.new()
|
var _accel := GSAITargetAcceleration.new()
|
||||||
var _angular_drag := 0.1
|
var _angular_drag := 0.1
|
||||||
var _cannon: Rect2
|
var _cannon: Rect2
|
||||||
var _color: Color
|
var _color: Color
|
||||||
@ -28,13 +28,13 @@ func _draw() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func setup(
|
func setup(
|
||||||
player_agent: GSTAgentLocation,
|
player_agent: GSAIAgentLocation,
|
||||||
align_tolerance: float,
|
align_tolerance: float,
|
||||||
deceleration_radius: float,
|
deceleration_radius: float,
|
||||||
angular_accel_max: float,
|
angular_accel_max: float,
|
||||||
angular_speed_max: float
|
angular_speed_max: float
|
||||||
) -> void:
|
) -> void:
|
||||||
face = GSTFace.new(agent, player_agent)
|
face = GSAIFace.new(agent, player_agent)
|
||||||
|
|
||||||
face.alignment_tolerance = align_tolerance
|
face.alignment_tolerance = align_tolerance
|
||||||
face.deceleration_radius = deceleration_radius
|
face.deceleration_radius = deceleration_radius
|
||||||
|
@ -2,17 +2,17 @@ extends KinematicBody2D
|
|||||||
|
|
||||||
|
|
||||||
var _velocity := Vector2.ZERO
|
var _velocity := Vector2.ZERO
|
||||||
var _accel := GSTTargetAcceleration.new()
|
var _accel := GSAITargetAcceleration.new()
|
||||||
var _valid := false
|
var _valid := false
|
||||||
var _drag := 0.1
|
var _drag := 0.1
|
||||||
|
|
||||||
|
|
||||||
onready var agent := GSTKinematicBody2DAgent.new(self)
|
onready var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
onready var path := GSTPath.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 := GSTFollowPath.new(agent, path, 0, 0)
|
onready var follow := GSAIFollowPath.new(agent, path, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
func setup(
|
func setup(
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
var separation: GSTSeparation
|
var separation: GSAISeparation
|
||||||
var cohesion: GSTCohesion
|
var cohesion: GSAICohesion
|
||||||
var proximity: GSTRadiusProximity
|
var proximity: GSAIRadiusProximity
|
||||||
var agent := GSTKinematicBody2DAgent.new(self)
|
var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
var blend := GSTBlend.new(agent)
|
var blend := GSAIBlend.new(agent)
|
||||||
var acceleration := GSTTargetAcceleration.new()
|
var acceleration := GSAITargetAcceleration.new()
|
||||||
var draw_proximity := false
|
var draw_proximity := false
|
||||||
|
|
||||||
var _color := Color.red
|
var _color := Color.red
|
||||||
@ -30,10 +30,10 @@ func setup(
|
|||||||
agent.linear_speed_max = linear_speed_max
|
agent.linear_speed_max = linear_speed_max
|
||||||
agent.linear_drag_percentage = 0.1
|
agent.linear_drag_percentage = 0.1
|
||||||
|
|
||||||
proximity = GSTRadiusProximity.new(agent, [], proximity_radius)
|
proximity = GSAIRadiusProximity.new(agent, [], proximity_radius)
|
||||||
separation = GSTSeparation.new(agent, proximity)
|
separation = GSAISeparation.new(agent, proximity)
|
||||||
separation.decay_coefficient = separation_decay_coefficient
|
separation.decay_coefficient = separation_decay_coefficient
|
||||||
cohesion = GSTCohesion.new(agent, proximity)
|
cohesion = GSAICohesion.new(agent, proximity)
|
||||||
blend.add(separation, separation_strength)
|
blend.add(separation, separation_strength)
|
||||||
blend.add(cohesion, cohesion_strength)
|
blend.add(cohesion, cohesion_strength)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export var linear_drag := 0.025
|
|||||||
var _linear_velocity := Vector2()
|
var _linear_velocity := Vector2()
|
||||||
var _angular_velocity := 0.0
|
var _angular_velocity := 0.0
|
||||||
|
|
||||||
onready var agent := GSTSteeringAgent.new()
|
onready var agent := GSAISteeringAgent.new()
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
@ -4,15 +4,15 @@ extends KinematicBody2D
|
|||||||
|
|
||||||
export var use_seek: bool = false
|
export var use_seek: bool = false
|
||||||
|
|
||||||
var _blend: GSTBlend
|
var _blend: GSAIBlend
|
||||||
|
|
||||||
var _linear_drag_coefficient := 0.025
|
var _linear_drag_coefficient := 0.025
|
||||||
var _angular_drag := 0.1
|
var _angular_drag := 0.1
|
||||||
var _direction_face := GSTAgentLocation.new()
|
var _direction_face := GSAIAgentLocation.new()
|
||||||
|
|
||||||
onready var agent := GSTKinematicBody2DAgent.new(self)
|
onready var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
onready var accel := GSTTargetAcceleration.new()
|
onready var accel := GSAITargetAcceleration.new()
|
||||||
onready var player_agent: GSTSteeringAgent = owner.find_node("Player", true, false).agent
|
onready var player_agent: GSAISteeringAgent = owner.find_node("Player", true, false).agent
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@ -35,8 +35,8 @@ func _physics_process(delta: float) -> void:
|
|||||||
rotation += agent.angular_velocity * delta
|
rotation += agent.angular_velocity * delta
|
||||||
|
|
||||||
var linear_velocity := (
|
var linear_velocity := (
|
||||||
GSTUtils.to_vector2(agent.linear_velocity) +
|
GSAIUtils.to_vector2(agent.linear_velocity) +
|
||||||
(GSTUtils.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(
|
||||||
@ -45,21 +45,21 @@ func _physics_process(delta: float) -> void:
|
|||||||
)
|
)
|
||||||
|
|
||||||
linear_velocity = move_and_slide(linear_velocity)
|
linear_velocity = move_and_slide(linear_velocity)
|
||||||
agent.linear_velocity = GSTUtils.to_vector3(linear_velocity)
|
agent.linear_velocity = GSAIUtils.to_vector3(linear_velocity)
|
||||||
|
|
||||||
|
|
||||||
func setup(predict_time: float, linear_speed_max: float, linear_accel_max: float) -> void:
|
func setup(predict_time: float, linear_speed_max: float, linear_accel_max: float) -> void:
|
||||||
var behavior: GSTSteeringBehavior
|
var behavior: GSAISteeringBehavior
|
||||||
if use_seek:
|
if use_seek:
|
||||||
behavior = GSTSeek.new(agent, player_agent)
|
behavior = GSAISeek.new(agent, player_agent)
|
||||||
else:
|
else:
|
||||||
behavior = GSTPursue.new(agent, player_agent, predict_time)
|
behavior = GSAIPursue.new(agent, player_agent, predict_time)
|
||||||
|
|
||||||
var orient_behavior := GSTFace.new(agent, _direction_face)
|
var orient_behavior := GSAIFace.new(agent, _direction_face)
|
||||||
orient_behavior.alignment_tolerance = deg2rad(5)
|
orient_behavior.alignment_tolerance = deg2rad(5)
|
||||||
orient_behavior.deceleration_radius = deg2rad(5)
|
orient_behavior.deceleration_radius = deg2rad(5)
|
||||||
|
|
||||||
_blend = GSTBlend.new(agent)
|
_blend = GSAIBlend.new(agent)
|
||||||
_blend.add(behavior, 1)
|
_blend.add(behavior, 1)
|
||||||
_blend.add(orient_behavior, 1)
|
_blend.add(orient_behavior, 1)
|
||||||
|
|
||||||
|
@ -19,32 +19,32 @@ var linear_drag := 0.1
|
|||||||
var angular_drag := 0.1
|
var angular_drag := 0.1
|
||||||
|
|
||||||
# Holds the linear and angular components calculated by our steering behaviors.
|
# Holds the linear and angular components calculated by our steering behaviors.
|
||||||
var acceleration := GSTTargetAcceleration.new()
|
var acceleration := GSAITargetAcceleration.new()
|
||||||
|
|
||||||
onready var current_health := health_max
|
onready var current_health := health_max
|
||||||
|
|
||||||
# GSTSteeringAgent holds our agent's position, orientation, maximum speed and acceleration.
|
# GSAISteeringAgent holds our agent's position, orientation, maximum speed and acceleration.
|
||||||
onready var agent := GSTSteeringAgent.new()
|
onready var agent := GSAISteeringAgent.new()
|
||||||
|
|
||||||
onready var player: Node = get_tree().get_nodes_in_group("Player")[0]
|
onready var player: Node = get_tree().get_nodes_in_group("Player")[0]
|
||||||
# This assumes that our player class will keep its own agent updated.
|
# This assumes that our player class will keep its own agent updated.
|
||||||
onready var player_agent: GSTSteeringAgent = player.agent
|
onready var player_agent: GSAISteeringAgent = player.agent
|
||||||
|
|
||||||
# Proximities represent an area with which an agent can identify where neighbors in its relevant
|
# Proximities represent an area with which an agent can identify where neighbors in its relevant
|
||||||
# group are. In our case, the group will feature the player, which will be used to avoid a
|
# group are. In our case, the group will feature the player, which will be used to avoid a
|
||||||
# collision with them. We use a radius proximity so the player is only relevant inside 100 pixels.
|
# collision with them. We use a radius proximity so the player is only relevant inside 100 pixels.
|
||||||
onready var proximity := GSTRadiusProximity.new(agent, [player_agent], 100)
|
onready var proximity := GSAIRadiusProximity.new(agent, [player_agent], 100)
|
||||||
|
|
||||||
# GSTBlend combines behaviors together, calculating all of their acceleration together and adding
|
# GSAIBlend combines behaviors together, calculating all of their acceleration together and adding
|
||||||
# them together, multiplied by a strength. We will have one for fleeing, and one for pursuing,
|
# them together, multiplied by a strength. We will have one for fleeing, and one for pursuing,
|
||||||
# toggling them depending on the agent's health. Since we want the agent to rotate AND move, then
|
# toggling them depending on the agent's health. Since we want the agent to rotate AND move, then
|
||||||
# we aim to blend them together.
|
# we aim to blend them together.
|
||||||
onready var flee_blend := GSTBlend.new(agent)
|
onready var flee_blend := GSAIBlend.new(agent)
|
||||||
onready var pursue_blend := GSTBlend.new(agent)
|
onready var pursue_blend := GSAIBlend.new(agent)
|
||||||
|
|
||||||
# GSTPriority will be the main steering behavior we use. It holds sub-behaviors and will pick the
|
# GSAIPriority will be the main steering behavior we use. It holds sub-behaviors and will pick the
|
||||||
# first one that returns non-zero acceleration, ignoring any afterwards.
|
# first one that returns non-zero acceleration, ignoring any afterwards.
|
||||||
onready var priority := GSTPriority.new(agent)
|
onready var priority := GSAIPriority.new(agent)
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@ -59,20 +59,20 @@ func _ready() -> void:
|
|||||||
# ---------- Configuration for our behaviors ----------
|
# ---------- Configuration for our behaviors ----------
|
||||||
# Pursue will happen while the agent is in good health. It produces acceleration that takes
|
# Pursue will happen while the agent is in good health. It produces acceleration that takes
|
||||||
# the agent on an intercept course with the target, predicting its position in the future.
|
# the agent on an intercept course with the target, predicting its position in the future.
|
||||||
var pursue := GSTPursue.new(agent, player_agent)
|
var pursue := GSAIPursue.new(agent, player_agent)
|
||||||
pursue.predict_time_max = 1.5
|
pursue.predict_time_max = 1.5
|
||||||
|
|
||||||
# Flee will happen while the agent is in bad health, so will start disabled. It produces
|
# Flee will happen while the agent is in bad health, so will start disabled. It produces
|
||||||
# acceleration that takes the agent directly away from the target with no prediction.
|
# acceleration that takes the agent directly away from the target with no prediction.
|
||||||
var flee := GSTFlee.new(agent, player_agent)
|
var flee := GSAIFlee.new(agent, player_agent)
|
||||||
|
|
||||||
# AvoidCollision tries to keep the agent from running into any of the neighbors found in its
|
# AvoidCollision tries to keep the agent from running into any of the neighbors found in its
|
||||||
# proximity group. In our case, this will be the player, if they are close enough.
|
# proximity group. In our case, this will be the player, if they are close enough.
|
||||||
var avoid := GSTAvoidCollisions.new(agent, proximity)
|
var avoid := GSAIAvoidCollisions.new(agent, proximity)
|
||||||
|
|
||||||
# Face turns the agent to keep looking towards its target. It will be enabled while the agent
|
# Face turns the agent to keep looking towards its target. It will be enabled while the agent
|
||||||
# is not fleeing due to low health. It tries to arrive 'on alignment' with 0 remaining velocity.
|
# is not fleeing due to low health. It tries to arrive 'on alignment' with 0 remaining velocity.
|
||||||
var face := GSTFace.new(agent, player_agent)
|
var face := GSAIFace.new(agent, player_agent)
|
||||||
|
|
||||||
# We use deg2rad because the math in the toolkit assumes radians.
|
# We use deg2rad because the math in the toolkit assumes radians.
|
||||||
# How close for the agent to be 'aligned', if not exact.
|
# How close for the agent to be 'aligned', if not exact.
|
||||||
@ -82,7 +82,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
# LookWhereYouGo turns the agent to keep looking towards its direction of travel. It will only
|
# LookWhereYouGo turns the agent to keep looking towards its direction of travel. It will only
|
||||||
# be enabled while the agent is at low health.
|
# be enabled while the agent is at low health.
|
||||||
var look := GSTLookWhereYouGo.new(agent)
|
var look := GSAILookWhereYouGo.new(agent)
|
||||||
# How close for the agent to be 'aligned', if not exact
|
# How close for the agent to be 'aligned', if not exact
|
||||||
look.alignment_tolerance = deg2rad(5)
|
look.alignment_tolerance = deg2rad(5)
|
||||||
# When to start slowing down.
|
# When to start slowing down.
|
||||||
|
@ -11,10 +11,10 @@ var velocity := Vector2.ZERO
|
|||||||
var angular_velocity := 0.0
|
var angular_velocity := 0.0
|
||||||
var direction := Vector2.RIGHT
|
var direction := Vector2.RIGHT
|
||||||
|
|
||||||
onready var agent := GSTSteeringAgent.new()
|
onready var agent := GSAISteeringAgent.new()
|
||||||
onready var proxy_target := GSTAgentLocation.new()
|
onready var proxy_target := GSAIAgentLocation.new()
|
||||||
onready var face := GSTFace.new(agent, proxy_target)
|
onready var face := GSAIFace.new(agent, proxy_target)
|
||||||
onready var accel := GSTTargetAcceleration.new()
|
onready var accel := GSAITargetAcceleration.new()
|
||||||
onready var bullets := owner.get_node("Bullets")
|
onready var bullets := owner.get_node("Bullets")
|
||||||
|
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
|
|
||||||
var movement := get_movement()
|
var movement := get_movement()
|
||||||
|
|
||||||
direction = GSTUtils.angle_to_vector2(rotation)
|
direction = GSAIUtils.angle_to_vector2(rotation)
|
||||||
|
|
||||||
velocity += direction * acceleration_max * movement
|
velocity += direction * acceleration_max * movement
|
||||||
velocity = velocity.clamped(speed_max)
|
velocity = velocity.clamped(speed_max)
|
||||||
|
@ -3,11 +3,11 @@ extends KinematicBody2D
|
|||||||
|
|
||||||
|
|
||||||
var speed: float
|
var speed: float
|
||||||
onready var agent := GSTAgentLocation.new()
|
onready var agent := GSAIAgentLocation.new()
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
agent.position = GSTUtils.to_vector3(global_position)
|
agent.position = GSAIUtils.to_vector3(global_position)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
@ -16,7 +16,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
return
|
return
|
||||||
|
|
||||||
move_and_slide(movement * speed)
|
move_and_slide(movement * speed)
|
||||||
agent.position = GSTUtils.to_vector3(global_position)
|
agent.position = GSAIUtils.to_vector3(global_position)
|
||||||
|
|
||||||
|
|
||||||
func _get_movement() -> Vector2:
|
func _get_movement() -> Vector2:
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
var player_agent: GSTAgentLocation
|
var player_agent: GSAIAgentLocation
|
||||||
var velocity := Vector2.ZERO
|
var velocity := Vector2.ZERO
|
||||||
var start_speed: float
|
var start_speed: float
|
||||||
var start_accel: float
|
var start_accel: float
|
||||||
var use_seek := true
|
var use_seek := true
|
||||||
|
|
||||||
onready var agent := GSTKinematicBody2DAgent.new(self)
|
onready var agent := GSAIKinematicBody2DAgent.new(self)
|
||||||
onready var accel := GSTTargetAcceleration.new()
|
onready var accel := GSAITargetAcceleration.new()
|
||||||
onready var seek := GSTSeek.new(agent, player_agent)
|
onready var seek := GSAISeek.new(agent, player_agent)
|
||||||
onready var flee := GSTFlee.new(agent, player_agent)
|
onready var flee := GSAIFlee.new(agent, player_agent)
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -9,187 +9,187 @@
|
|||||||
config_version=4
|
config_version=4
|
||||||
|
|
||||||
_global_script_classes=[ {
|
_global_script_classes=[ {
|
||||||
"base": "CenterContainer",
|
"base": "Control",
|
||||||
"class": "DemoPickerUI",
|
"class": "DemoPickerUI",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://demos/DemoPickerUI.gd"
|
"path": "res://demos/DemoPickerUI.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "GSTAgentLocation",
|
"class": "GSAIAgentLocation",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTAgentLocation.gd"
|
"path": "res://src/GSAIAgentLocation.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTArrive",
|
"class": "GSAIArrive",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTArrive.gd"
|
"path": "res://src/Behaviors/GSAIArrive.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTGroupBehavior",
|
"base": "GSAIGroupBehavior",
|
||||||
"class": "GSTAvoidCollisions",
|
"class": "GSAIAvoidCollisions",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTAvoidCollisions.gd"
|
"path": "res://src/Behaviors/GSAIAvoidCollisions.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTBlend",
|
"class": "GSAIBlend",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTBlend.gd"
|
"path": "res://src/Behaviors/GSAIBlend.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTGroupBehavior",
|
"base": "GSAIGroupBehavior",
|
||||||
"class": "GSTCohesion",
|
"class": "GSAICohesion",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTCohesion.gd"
|
"path": "res://src/Behaviors/GSAICohesion.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTPursue",
|
"base": "GSAIPursue",
|
||||||
"class": "GSTEvade",
|
"class": "GSAIEvade",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTEvade.gd"
|
"path": "res://src/Behaviors/GSAIEvade.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTMatchOrientation",
|
"base": "GSAIMatchOrientation",
|
||||||
"class": "GSTFace",
|
"class": "GSAIFace",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTFace.gd"
|
"path": "res://src/Behaviors/GSAIFace.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSeek",
|
"base": "GSAISeek",
|
||||||
"class": "GSTFlee",
|
"class": "GSAIFlee",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTFlee.gd"
|
"path": "res://src/Behaviors/GSAIFlee.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTArrive",
|
"base": "GSAIArrive",
|
||||||
"class": "GSTFollowPath",
|
"class": "GSAIFollowPath",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTFollowPath.gd"
|
"path": "res://src/Behaviors/GSAIFollowPath.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTGroupBehavior",
|
"class": "GSAIGroupBehavior",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTGroupBehavior.gd"
|
"path": "res://src/GSAIGroupBehavior.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTProximity",
|
"base": "GSAIProximity",
|
||||||
"class": "GSTInfiniteProximity",
|
"class": "GSAIInfiniteProximity",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Proximities/GSTInfiniteProximity.gd"
|
"path": "res://src/Proximities/GSAIInfiniteProximity.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSpecializedAgent",
|
"base": "GSAISpecializedAgent",
|
||||||
"class": "GSTKinematicBody2DAgent",
|
"class": "GSAIKinematicBody2DAgent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Agents/GSTKinematicBody2DAgent.gd"
|
"path": "res://src/Agents/GSAIKinematicBody2DAgent.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSpecializedAgent",
|
"base": "GSAISpecializedAgent",
|
||||||
"class": "GSTKinematicBodyAgent",
|
"class": "GSAIKinematicBodyAgent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Agents/GSTKinematicBodyAgent.gd"
|
"path": "res://src/Agents/GSAIKinematicBodyAgent.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTMatchOrientation",
|
"base": "GSAIMatchOrientation",
|
||||||
"class": "GSTLookWhereYouGo",
|
"class": "GSAILookWhereYouGo",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTLookWhereYouGo.gd"
|
"path": "res://src/Behaviors/GSAILookWhereYouGo.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTMatchOrientation",
|
"class": "GSAIMatchOrientation",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTMatchOrientation.gd"
|
"path": "res://src/Behaviors/GSAIMatchOrientation.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "GSTPath",
|
"class": "GSAIPath",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTPath.gd"
|
"path": "res://src/GSAIPath.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTPriority",
|
"class": "GSAIPriority",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTPriority.gd"
|
"path": "res://src/Behaviors/GSAIPriority.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "GSTProximity",
|
"class": "GSAIProximity",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Proximities/GSTProximity.gd"
|
"path": "res://src/Proximities/GSAIProximity.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTPursue",
|
"class": "GSAIPursue",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTPursue.gd"
|
"path": "res://src/Behaviors/GSAIPursue.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTProximity",
|
"base": "GSAIProximity",
|
||||||
"class": "GSTRadiusProximity",
|
"class": "GSAIRadiusProximity",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Proximities/GSTRadiusProximity.gd"
|
"path": "res://src/Proximities/GSAIRadiusProximity.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSpecializedAgent",
|
"base": "GSAISpecializedAgent",
|
||||||
"class": "GSTRigidBody2DAgent",
|
"class": "GSAIRigidBody2DAgent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Agents/GSTRigidBody2DAgent.gd"
|
"path": "res://src/Agents/GSAIRigidBody2DAgent.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSpecializedAgent",
|
"base": "GSAISpecializedAgent",
|
||||||
"class": "GSTRigidBodyAgent",
|
"class": "GSAIRigidBodyAgent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Agents/GSTRigidBodyAgent.gd"
|
"path": "res://src/Agents/GSAIRigidBodyAgent.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringBehavior",
|
"base": "GSAISteeringBehavior",
|
||||||
"class": "GSTSeek",
|
"class": "GSAISeek",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTSeek.gd"
|
"path": "res://src/Behaviors/GSAISeek.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTGroupBehavior",
|
"base": "GSAIGroupBehavior",
|
||||||
"class": "GSTSeparation",
|
"class": "GSAISeparation",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Behaviors/GSTSeparation.gd"
|
"path": "res://src/Behaviors/GSAISeparation.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTSteeringAgent",
|
"base": "GSAISteeringAgent",
|
||||||
"class": "GSTSpecializedAgent",
|
"class": "GSAISpecializedAgent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/Agents/GSTSpecializedAgent.gd"
|
"path": "res://src/Agents/GSAISpecializedAgent.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "GSTAgentLocation",
|
"base": "GSAIAgentLocation",
|
||||||
"class": "GSTSteeringAgent",
|
"class": "GSAISteeringAgent",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTSteeringAgent.gd"
|
"path": "res://src/GSAISteeringAgent.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "GSTSteeringBehavior",
|
"class": "GSAISteeringBehavior",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTSteeringBehavior.gd"
|
"path": "res://src/GSAISteeringBehavior.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "GSTTargetAcceleration",
|
"class": "GSAITargetAcceleration",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTTargetAcceleration.gd"
|
"path": "res://src/GSAITargetAcceleration.gd"
|
||||||
}, {
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "GSTUtils",
|
"class": "GSAIUtils",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTUtils.gd"
|
"path": "res://src/GSAIUtils.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"DemoPickerUI": "",
|
"DemoPickerUI": "",
|
||||||
"GSTAgentLocation": "",
|
"GSAIAgentLocation": "",
|
||||||
"GSTArrive": "",
|
"GSAIArrive": "",
|
||||||
"GSTAvoidCollisions": "",
|
"GSAIAvoidCollisions": "",
|
||||||
"GSTBlend": "",
|
"GSAIBlend": "",
|
||||||
"GSTCohesion": "",
|
"GSAICohesion": "",
|
||||||
"GSTEvade": "",
|
"GSAIEvade": "",
|
||||||
"GSTFace": "",
|
"GSAIFace": "",
|
||||||
"GSTFlee": "",
|
"GSAIFlee": "",
|
||||||
"GSTFollowPath": "",
|
"GSAIFollowPath": "",
|
||||||
"GSTGroupBehavior": "",
|
"GSAIGroupBehavior": "",
|
||||||
"GSTInfiniteProximity": "",
|
"GSAIInfiniteProximity": "",
|
||||||
"GSTKinematicBody2DAgent": "",
|
"GSAIKinematicBody2DAgent": "",
|
||||||
"GSTKinematicBodyAgent": "",
|
"GSAIKinematicBodyAgent": "",
|
||||||
"GSTLookWhereYouGo": "",
|
"GSAILookWhereYouGo": "",
|
||||||
"GSTMatchOrientation": "",
|
"GSAIMatchOrientation": "",
|
||||||
"GSTPath": "",
|
"GSAIPath": "",
|
||||||
"GSTPriority": "",
|
"GSAIPriority": "",
|
||||||
"GSTProximity": "",
|
"GSAIProximity": "",
|
||||||
"GSTPursue": "",
|
"GSAIPursue": "",
|
||||||
"GSTRadiusProximity": "",
|
"GSAIRadiusProximity": "",
|
||||||
"GSTRigidBody2DAgent": "",
|
"GSAIRigidBody2DAgent": "",
|
||||||
"GSTRigidBodyAgent": "",
|
"GSAIRigidBodyAgent": "",
|
||||||
"GSTSeek": "",
|
"GSAISeek": "",
|
||||||
"GSTSeparation": "",
|
"GSAISeparation": "",
|
||||||
"GSTSpecializedAgent": "",
|
"GSAISpecializedAgent": "",
|
||||||
"GSTSteeringAgent": "",
|
"GSAISteeringAgent": "",
|
||||||
"GSTSteeringBehavior": "",
|
"GSAISteeringBehavior": "",
|
||||||
"GSTTargetAcceleration": "",
|
"GSAITargetAcceleration": "",
|
||||||
"GSTUtils": ""
|
"GSAIUtils": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# A specialized steering agent that updates itself every frame so the user does
|
# A specialized steering agent that updates itself every frame so the user does
|
||||||
# not have to using a KinematicBody2D
|
# not have to using a KinematicBody2D
|
||||||
extends GSTSpecializedAgent
|
extends GSAISpecializedAgent
|
||||||
class_name GSTKinematicBody2DAgent
|
class_name GSAIKinematicBody2DAgent
|
||||||
|
|
||||||
|
|
||||||
# SLIDE uses `move_and_slide`
|
# SLIDE uses `move_and_slide`
|
||||||
@ -31,7 +31,7 @@ func _init(body: KinematicBody2D, movement_type: int = MovementType.SLIDE) -> vo
|
|||||||
|
|
||||||
# Moves the agent's `body` by target `acceleration`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
match movement_type:
|
match movement_type:
|
||||||
MovementType.COLLIDE:
|
MovementType.COLLIDE:
|
||||||
@ -45,34 +45,34 @@ func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _apply_sliding_steering(accel: Vector3) -> void:
|
func _apply_sliding_steering(accel: Vector3) -> void:
|
||||||
var velocity := GSTUtils.to_vector2(linear_velocity + accel).clamped(linear_speed_max)
|
var velocity := GSAIUtils.to_vector2(linear_velocity + accel).clamped(linear_speed_max)
|
||||||
if apply_linear_drag:
|
if apply_linear_drag:
|
||||||
velocity = velocity.linear_interpolate(Vector2.ZERO, linear_drag_percentage)
|
velocity = velocity.linear_interpolate(Vector2.ZERO, linear_drag_percentage)
|
||||||
velocity = body.move_and_slide(velocity)
|
velocity = body.move_and_slide(velocity)
|
||||||
if calculate_velocities:
|
if calculate_velocities:
|
||||||
linear_velocity = GSTUtils.to_vector3(velocity)
|
linear_velocity = GSAIUtils.to_vector3(velocity)
|
||||||
|
|
||||||
|
|
||||||
func _apply_collide_steering(accel: Vector3, delta: float) -> void:
|
func _apply_collide_steering(accel: Vector3, delta: float) -> void:
|
||||||
var velocity := GSTUtils.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,
|
Vector3.ZERO,
|
||||||
linear_drag_percentage
|
linear_drag_percentage
|
||||||
)
|
)
|
||||||
body.move_and_collide(GSTUtils.to_vector2(velocity) * delta)
|
body.move_and_collide(GSAIUtils.to_vector2(velocity) * delta)
|
||||||
if calculate_velocities:
|
if calculate_velocities:
|
||||||
linear_velocity = velocity
|
linear_velocity = velocity
|
||||||
|
|
||||||
|
|
||||||
func _apply_position_steering(accel: Vector3, delta: float) -> void:
|
func _apply_position_steering(accel: Vector3, delta: float) -> void:
|
||||||
var velocity := GSTUtils.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,
|
Vector3.ZERO,
|
||||||
linear_drag_percentage
|
linear_drag_percentage
|
||||||
)
|
)
|
||||||
body.global_position += GSTUtils.to_vector2(velocity) * delta
|
body.global_position += GSAIUtils.to_vector2(velocity) * delta
|
||||||
if calculate_velocities:
|
if calculate_velocities:
|
||||||
linear_velocity = velocity
|
linear_velocity = velocity
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ func _set_body(value: KinematicBody2D) -> void:
|
|||||||
_last_position = body.global_position
|
_last_position = body.global_position
|
||||||
_last_orientation = body.rotation
|
_last_orientation = body.rotation
|
||||||
|
|
||||||
position = GSTUtils.to_vector3(_last_position)
|
position = GSAIUtils.to_vector3(_last_position)
|
||||||
orientation = _last_orientation
|
orientation = _last_orientation
|
||||||
|
|
||||||
|
|
||||||
@ -100,15 +100,15 @@ func _on_SceneTree_physics_frame() -> void:
|
|||||||
var current_position: Vector2 = body.global_position
|
var current_position: Vector2 = body.global_position
|
||||||
var current_orientation: float = body.rotation
|
var current_orientation: float = body.rotation
|
||||||
|
|
||||||
position = GSTUtils.to_vector3(current_position)
|
position = GSAIUtils.to_vector3(current_position)
|
||||||
orientation = current_orientation
|
orientation = current_orientation
|
||||||
|
|
||||||
if calculate_velocities:
|
if calculate_velocities:
|
||||||
if _applied_steering:
|
if _applied_steering:
|
||||||
_applied_steering = false
|
_applied_steering = false
|
||||||
else:
|
else:
|
||||||
linear_velocity = GSTUtils.clampedv3(
|
linear_velocity = GSAIUtils.clampedv3(
|
||||||
GSTUtils.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:
|
@ -1,7 +1,7 @@
|
|||||||
# A specialized steering agent that updates itself every frame so the user does
|
# A specialized steering agent that updates itself every frame so the user does
|
||||||
# not have to using a KinematicBody
|
# not have to using a KinematicBody
|
||||||
extends GSTSpecializedAgent
|
extends GSAISpecializedAgent
|
||||||
class_name GSTKinematicBodyAgent
|
class_name GSAIKinematicBodyAgent
|
||||||
|
|
||||||
# SLIDE uses `move_and_slide`
|
# SLIDE uses `move_and_slide`
|
||||||
# COLLIDE uses `move_and_collide`
|
# COLLIDE uses `move_and_collide`
|
||||||
@ -30,7 +30,7 @@ func _init(body: KinematicBody, movement_type: int = MovementType.SLIDE) -> void
|
|||||||
|
|
||||||
# Moves the agent's `body` by target `acceleration`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
match movement_type:
|
match movement_type:
|
||||||
MovementType.COLLIDE:
|
MovementType.COLLIDE:
|
||||||
@ -44,7 +44,7 @@ func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _apply_sliding_steering(accel: Vector3) -> void:
|
func _apply_sliding_steering(accel: Vector3) -> void:
|
||||||
var velocity := GSTUtils.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(Vector3.ZERO, linear_drag_percentage)
|
velocity = velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage)
|
||||||
velocity = body.move_and_slide(velocity)
|
velocity = body.move_and_slide(velocity)
|
||||||
@ -53,7 +53,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 := GSTUtils.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,
|
Vector3.ZERO,
|
||||||
@ -65,7 +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 := GSTUtils.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,
|
Vector3.ZERO,
|
||||||
@ -106,7 +106,7 @@ func _on_SceneTree_physics_frame() -> void:
|
|||||||
if _applied_steering:
|
if _applied_steering:
|
||||||
_applied_steering = false
|
_applied_steering = false
|
||||||
else:
|
else:
|
||||||
linear_velocity = GSTUtils.clampedv3(
|
linear_velocity = GSAIUtils.clampedv3(
|
||||||
_last_position - current_position,
|
_last_position - current_position,
|
||||||
linear_speed_max
|
linear_speed_max
|
||||||
)
|
)
|
@ -1,7 +1,7 @@
|
|||||||
# A specialized steering agent that updates itself every frame so the user does
|
# A specialized steering agent that updates itself every frame so the user does
|
||||||
# not have to using a RigidBody2D
|
# not have to using a RigidBody2D
|
||||||
extends GSTSpecializedAgent
|
extends GSAISpecializedAgent
|
||||||
class_name GSTRigidBody2DAgent
|
class_name GSAIRigidBody2DAgent
|
||||||
|
|
||||||
|
|
||||||
# The RigidBody2D to keep track of
|
# The RigidBody2D to keep track of
|
||||||
@ -19,12 +19,12 @@ func _init(body: RigidBody2D) -> void:
|
|||||||
|
|
||||||
# Moves the agent's `body` by target `acceleration`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
body.apply_central_impulse(GSTUtils.to_vector2(acceleration.linear))
|
body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear))
|
||||||
body.apply_torque_impulse(acceleration.angular)
|
body.apply_torque_impulse(acceleration.angular)
|
||||||
if calculate_velocities:
|
if calculate_velocities:
|
||||||
linear_velocity = GSTUtils.to_vector3(body.linear_velocity)
|
linear_velocity = GSAIUtils.to_vector3(body.linear_velocity)
|
||||||
angular_velocity = body.angular_velocity
|
angular_velocity = body.angular_velocity
|
||||||
|
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ func _set_body(value: RigidBody2D) -> void:
|
|||||||
_last_position = body.global_position
|
_last_position = body.global_position
|
||||||
_last_orientation = body.rotation
|
_last_orientation = body.rotation
|
||||||
|
|
||||||
position = GSTUtils.to_vector3(_last_position)
|
position = GSAIUtils.to_vector3(_last_position)
|
||||||
orientation = _last_orientation
|
orientation = _last_orientation
|
||||||
|
|
||||||
|
|
||||||
@ -47,12 +47,12 @@ func _on_SceneTree_frame() -> void:
|
|||||||
var current_position: Vector2 = body.global_position
|
var current_position: Vector2 = body.global_position
|
||||||
var current_orientation: float = body.rotation
|
var current_orientation: float = body.rotation
|
||||||
|
|
||||||
position = GSTUtils.to_vector3(current_position)
|
position = GSAIUtils.to_vector3(current_position)
|
||||||
orientation = current_orientation
|
orientation = current_orientation
|
||||||
|
|
||||||
if calculate_velocities:
|
if calculate_velocities:
|
||||||
if _applied_steering:
|
if _applied_steering:
|
||||||
_applied_steering = false
|
_applied_steering = false
|
||||||
else:
|
else:
|
||||||
linear_velocity = GSTUtils.to_vector3(body.linear_velocity)
|
linear_velocity = GSAIUtils.to_vector3(body.linear_velocity)
|
||||||
angular_velocity = body.angular_velocity
|
angular_velocity = body.angular_velocity
|
@ -1,7 +1,7 @@
|
|||||||
# A specialized steering agent that updates itself every frame so the user does
|
# A specialized steering agent that updates itself every frame so the user does
|
||||||
# not have to using a RigidBody
|
# not have to using a RigidBody
|
||||||
extends GSTSpecializedAgent
|
extends GSAISpecializedAgent
|
||||||
class_name GSTRigidBodyAgent
|
class_name GSAIRigidBodyAgent
|
||||||
|
|
||||||
|
|
||||||
# The RigidBody to keep track of
|
# The RigidBody to keep track of
|
||||||
@ -21,7 +21,7 @@ func _init(body: RigidBody) -> void:
|
|||||||
|
|
||||||
# Moves the agent's `body` by target `acceleration`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
body.apply_central_impulse(acceleration.linear)
|
body.apply_central_impulse(acceleration.linear)
|
||||||
body.apply_torque_impulse(Vector3.UP * acceleration.angular)
|
body.apply_torque_impulse(Vector3.UP * acceleration.angular)
|
@ -1,8 +1,8 @@
|
|||||||
# A base class for a specialized steering agent that updates itself every frame
|
# A base class for a specialized steering agent that updates itself every frame
|
||||||
# so the user does not have to. All other specialized agents derive from this.
|
# so the user does not have to. All other specialized agents derive from this.
|
||||||
# tags: abstract
|
# tags: abstract
|
||||||
extends GSTSteeringAgent
|
extends GSAISteeringAgent
|
||||||
class_name GSTSpecializedAgent
|
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
|
||||||
@ -36,5 +36,5 @@ var _applied_steering := false
|
|||||||
|
|
||||||
# Moves the agent's body by target `acceleration`.
|
# Moves the agent's body by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void:
|
||||||
pass
|
pass
|
@ -1,11 +1,11 @@
|
|||||||
# Calculates acceleration to take an agent to its target's location. The
|
# Calculates acceleration to take an agent to its target's location. The
|
||||||
# calculation attempts to arrive with zero remaining velocity.
|
# calculation attempts to arrive with zero remaining velocity.
|
||||||
class_name GSTArrive
|
class_name GSAIArrive
|
||||||
extends GSTSteeringBehavior
|
extends GSAISteeringBehavior
|
||||||
|
|
||||||
|
|
||||||
# Target agent to arrive to.
|
# Target agent to arrive to.
|
||||||
var target: GSTAgentLocation
|
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
|
||||||
# arrived.
|
# arrived.
|
||||||
var arrival_tolerance: float
|
var arrival_tolerance: float
|
||||||
@ -15,11 +15,11 @@ var deceleration_radius: float
|
|||||||
var time_to_reach := 0.1
|
var time_to_reach := 0.1
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void:
|
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void:
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|
||||||
|
|
||||||
func _arrive(acceleration: GSTTargetAcceleration, target_position: Vector3) -> void:
|
func _arrive(acceleration: GSAITargetAcceleration, target_position: Vector3) -> void:
|
||||||
var to_target := target_position - agent.position
|
var to_target := target_position - agent.position
|
||||||
var distance := to_target.length()
|
var distance := to_target.length()
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ func _arrive(acceleration: GSTTargetAcceleration, target_position: Vector3) -> v
|
|||||||
|
|
||||||
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 = GSTUtils.clampedv3(desired_velocity, agent.linear_acceleration_max)
|
acceleration.linear = GSAIUtils.clampedv3(desired_velocity, agent.linear_acceleration_max)
|
||||||
acceleration.angular = 0
|
acceleration.angular = 0
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
_arrive(acceleration, target.position)
|
_arrive(acceleration, target.position)
|
@ -1,10 +1,10 @@
|
|||||||
# Steers the agent to avoid obstacles in its path. Approximates obstacles as
|
# Steers the agent to avoid obstacles in its path. Approximates obstacles as
|
||||||
# spheres.
|
# spheres.
|
||||||
class_name GSTAvoidCollisions
|
class_name GSAIAvoidCollisions
|
||||||
extends GSTGroupBehavior
|
extends GSAIGroupBehavior
|
||||||
|
|
||||||
|
|
||||||
var _first_neighbor: GSTSteeringAgent
|
var _first_neighbor: GSAISteeringAgent
|
||||||
var _shortest_time: float
|
var _shortest_time: float
|
||||||
var _first_minimum_separation: float
|
var _first_minimum_separation: float
|
||||||
var _first_distance: float
|
var _first_distance: float
|
||||||
@ -12,11 +12,11 @@ var _first_relative_position: Vector3
|
|||||||
var _first_relative_velocity: Vector3
|
var _first_relative_velocity: Vector3
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void:
|
func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
_shortest_time = INF
|
_shortest_time = INF
|
||||||
_first_neighbor = null
|
_first_neighbor = null
|
||||||
_first_minimum_separation = 0
|
_first_minimum_separation = 0
|
||||||
@ -41,7 +41,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
|||||||
# Callback for the proximity to call when finding neighbors. Keeps track of every `neighbor`
|
# Callback for the proximity to call when finding neighbors. Keeps track of every `neighbor`
|
||||||
# that was found but only keeps the one the owning agent will most likely collide with.
|
# that was found but only keeps the one the owning agent will most likely collide with.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _report_neighbor(neighbor: GSTSteeringAgent) -> bool:
|
func _report_neighbor(neighbor: GSAISteeringAgent) -> bool:
|
||||||
var relative_position := neighbor.position - agent.position
|
var relative_position := neighbor.position - agent.position
|
||||||
var relative_velocity := neighbor.linear_velocity - agent.linear_velocity
|
var relative_velocity := neighbor.linear_velocity - agent.linear_velocity
|
||||||
var relative_speed_squared := relative_velocity.length_squared()
|
var relative_speed_squared := relative_velocity.length_squared()
|
@ -3,23 +3,23 @@
|
|||||||
#
|
#
|
||||||
# Stores the behaviors internally as dictionaries of the form
|
# Stores the behaviors internally as dictionaries of the form
|
||||||
# {
|
# {
|
||||||
# behavior : GSTSteeringBehavior,
|
# behavior : GSAISteeringBehavior,
|
||||||
# weight : float
|
# weight : float
|
||||||
# }
|
# }
|
||||||
class_name GSTBlend
|
class_name GSAIBlend
|
||||||
extends GSTSteeringBehavior
|
extends GSAISteeringBehavior
|
||||||
|
|
||||||
|
|
||||||
var _behaviors := []
|
var _behaviors := []
|
||||||
var _accel := GSTTargetAcceleration.new()
|
var _accel := GSAITargetAcceleration.new()
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent).(agent) -> void:
|
func _init(agent: GSAISteeringAgent).(agent) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Appends a behavior to the internal array along with its `weight`.
|
# Appends a behavior to the internal array along with its `weight`.
|
||||||
func add(behavior: GSTSteeringBehavior, weight: float) -> void:
|
func add(behavior: GSAISteeringBehavior, weight: float) -> void:
|
||||||
behavior.agent = agent
|
behavior.agent = agent
|
||||||
_behaviors.append({behavior = behavior, weight = weight})
|
_behaviors.append({behavior = behavior, weight = weight})
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func get_behavior_at(index: int) -> Dictionary:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(blended_accel: GSTTargetAcceleration) -> void:
|
func _calculate_steering(blended_accel: GSAITargetAcceleration) -> void:
|
||||||
blended_accel.set_zero()
|
blended_accel.set_zero()
|
||||||
|
|
||||||
for i in range(_behaviors.size()):
|
for i in range(_behaviors.size()):
|
||||||
@ -42,7 +42,7 @@ func _calculate_steering(blended_accel: GSTTargetAcceleration) -> void:
|
|||||||
|
|
||||||
blended_accel.add_scaled_accel(_accel, bw.weight)
|
blended_accel.add_scaled_accel(_accel, bw.weight)
|
||||||
|
|
||||||
blended_accel.linear = GSTUtils.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,
|
@ -1,17 +1,17 @@
|
|||||||
# Calculates an acceleration that attempts to move the agent towards the center
|
# Calculates an acceleration that attempts to move the agent towards the center
|
||||||
# of mass of the agents in the area defined by the `GSTProximity`.
|
# of mass of the agents in the area defined by the `GSAIProximity`.
|
||||||
class_name GSTCohesion
|
class_name GSAICohesion
|
||||||
extends GSTGroupBehavior
|
extends GSAIGroupBehavior
|
||||||
|
|
||||||
|
|
||||||
var _center_of_mass: Vector3
|
var _center_of_mass: Vector3
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void:
|
func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
acceleration.set_zero()
|
acceleration.set_zero()
|
||||||
_center_of_mass = Vector3.ZERO
|
_center_of_mass = Vector3.ZERO
|
||||||
var neighbor_count = proximity._find_neighbors(_callback)
|
var neighbor_count = proximity._find_neighbors(_callback)
|
||||||
@ -23,6 +23,6 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
|||||||
# 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
|
||||||
# to the center of mass of the group.
|
# to the center of mass of the group.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _report_neighbor(neighbor: GSTSteeringAgent) -> bool:
|
func _report_neighbor(neighbor: GSAISteeringAgent) -> bool:
|
||||||
_center_of_mass += neighbor.position
|
_center_of_mass += neighbor.position
|
||||||
return true
|
return true
|
@ -1,12 +1,12 @@
|
|||||||
# Calculates acceleration to take an agent away from where a target agent is
|
# Calculates acceleration to take an agent away from where a target agent is
|
||||||
# moving.
|
# moving.
|
||||||
class_name GSTEvade
|
class_name GSAIEvade
|
||||||
extends GSTPursue
|
extends GSAIPursue
|
||||||
|
|
||||||
|
|
||||||
func _init(
|
func _init(
|
||||||
agent: GSTSteeringAgent,
|
agent: GSAISteeringAgent,
|
||||||
target: GSTSteeringAgent,
|
target: GSAISteeringAgent,
|
||||||
predict_time_max := 1.0).(agent, target, predict_time_max):
|
predict_time_max := 1.0).(agent, target, predict_time_max):
|
||||||
pass
|
pass
|
||||||
|
|
@ -1,23 +1,23 @@
|
|||||||
# Calculates angular acceleration to rotate a target to face its target's
|
# Calculates angular acceleration to rotate a target to face its target's
|
||||||
# position. The behavior attemps to arrive with zero remaining angular velocity.
|
# position. The behavior attemps to arrive with zero remaining angular velocity.
|
||||||
class_name GSTFace
|
class_name GSAIFace
|
||||||
extends GSTMatchOrientation
|
extends GSAIMatchOrientation
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void:
|
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent, target) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _face(acceleration: GSTTargetAcceleration, target_position: Vector3) -> void:
|
func _face(acceleration: GSAITargetAcceleration, target_position: Vector3) -> void:
|
||||||
var to_target := target_position - agent.position
|
var to_target := target_position - agent.position
|
||||||
var distance_squared := to_target.length_squared()
|
var distance_squared := to_target.length_squared()
|
||||||
|
|
||||||
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 = GSTUtils.vector3_to_angle(to_target)
|
var orientation = GSAIUtils.vector3_to_angle(to_target)
|
||||||
_match_orientation(acceleration, orientation)
|
_match_orientation(acceleration, orientation)
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
_face(acceleration, target.position)
|
_face(acceleration, target.position)
|
@ -1,13 +1,13 @@
|
|||||||
# Calculates acceleration to take an agent directly away from a target agent.
|
# Calculates acceleration to take an agent directly away from a target agent.
|
||||||
class_name GSTFlee
|
class_name GSAIFlee
|
||||||
extends GSTSeek
|
extends GSAISeek
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void:
|
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent, target) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> 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
|
@ -1,14 +1,14 @@
|
|||||||
# Produces a linear acceleration that moves the agent along the specified path.
|
# Produces a linear acceleration that moves the agent along the specified path.
|
||||||
class_name GSTFollowPath
|
class_name GSAIFollowPath
|
||||||
extends GSTArrive
|
extends GSAIArrive
|
||||||
|
|
||||||
|
|
||||||
# The path to follow and travel along.
|
# The path to follow and travel along.
|
||||||
var path: GSTPath
|
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.
|
||||||
var path_offset := 0.0
|
var path_offset := 0.0
|
||||||
|
|
||||||
# Whether to use `GSTArrive` behavior on an open path.
|
# Whether to use `GSAIArrive` behavior on an open path.
|
||||||
var is_arrive_enabled := true
|
var is_arrive_enabled := true
|
||||||
# The amount of time in the future to predict the owning agent's position along
|
# 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.
|
# the path. Setting it to 0.0 will force non-predictive path following.
|
||||||
@ -16,8 +16,8 @@ var prediction_time := 0.0
|
|||||||
|
|
||||||
|
|
||||||
func _init(
|
func _init(
|
||||||
agent: GSTSteeringAgent,
|
agent: GSAISteeringAgent,
|
||||||
path: GSTPath,
|
path: GSAIPath,
|
||||||
path_offset := 0.0,
|
path_offset := 0.0,
|
||||||
prediction_time := 0.0).(agent, null) -> void:
|
prediction_time := 0.0).(agent, null) -> void:
|
||||||
self.path = path
|
self.path = path
|
||||||
@ -25,7 +25,7 @@ func _init(
|
|||||||
self.prediction_time = prediction_time
|
self.prediction_time = prediction_time
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
var location := (
|
var location := (
|
||||||
agent.position if prediction_time == 0
|
agent.position if prediction_time == 0
|
||||||
else agent.position + (agent.linear_velocity * prediction_time))
|
else agent.position + (agent.linear_velocity * prediction_time))
|
@ -1,16 +1,16 @@
|
|||||||
# Calculates an angular acceleration to match an agent's orientation to its
|
# Calculates an angular acceleration to match an agent's orientation to its
|
||||||
# direction of travel.
|
# direction of travel.
|
||||||
class_name GSTLookWhereYouGo
|
class_name GSAILookWhereYouGo
|
||||||
extends GSTMatchOrientation
|
extends GSAIMatchOrientation
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent).(agent, null) -> void:
|
func _init(agent: GSAISteeringAgent).(agent, null) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(accel: GSTTargetAcceleration) -> void:
|
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 := GSTUtils.vector3_to_angle(agent.linear_velocity)
|
var orientation := GSAIUtils.vector3_to_angle(agent.linear_velocity)
|
||||||
_match_orientation(accel, orientation)
|
_match_orientation(accel, orientation)
|
@ -1,12 +1,12 @@
|
|||||||
# Calculates an angular acceleration to match an agent's orientation to that of
|
# 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
|
# its target. Attempts to make the agent arrive with zero remaining angular
|
||||||
# velocity.
|
# velocity.
|
||||||
class_name GSTMatchOrientation
|
class_name GSAIMatchOrientation
|
||||||
extends GSTSteeringBehavior
|
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: GSTAgentLocation
|
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
|
||||||
# enough to be matching the target agent's rotation.
|
# enough to be matching the target agent's rotation.
|
||||||
var alignment_tolerance: float
|
var alignment_tolerance: float
|
||||||
@ -16,11 +16,11 @@ var deceleration_radius: float
|
|||||||
var time_to_reach: float = 0.1
|
var time_to_reach: float = 0.1
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void:
|
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void:
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|
||||||
|
|
||||||
func _match_orientation(acceleration: GSTTargetAcceleration, desired_orientation: float) -> void:
|
func _match_orientation(acceleration: GSAITargetAcceleration, desired_orientation: float) -> void:
|
||||||
var rotation := wrapf(desired_orientation - agent.orientation, -PI, PI)
|
var rotation := wrapf(desired_orientation - agent.orientation, -PI, PI)
|
||||||
|
|
||||||
var rotation_size := abs(rotation)
|
var rotation_size := abs(rotation)
|
||||||
@ -44,5 +44,5 @@ func _match_orientation(acceleration: GSTTargetAcceleration, desired_orientation
|
|||||||
acceleration.linear = Vector3.ZERO
|
acceleration.linear = Vector3.ZERO
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
_match_orientation(acceleration, target.orientation)
|
_match_orientation(acceleration, target.orientation)
|
@ -1,7 +1,7 @@
|
|||||||
# Container for multiple behaviors that returns the result of the first child
|
# Container for multiple behaviors that returns the result of the first child
|
||||||
# behavior with non-zero acceleration.
|
# behavior with non-zero acceleration.
|
||||||
class_name GSTPriority
|
class_name GSAIPriority
|
||||||
extends GSTSteeringBehavior
|
extends GSAISteeringBehavior
|
||||||
|
|
||||||
|
|
||||||
var _behaviors := []
|
var _behaviors := []
|
||||||
@ -13,25 +13,25 @@ var last_selected_index: int
|
|||||||
var zero_threshold: float
|
var zero_threshold: float
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, zero_threshold := 0.001).(agent) -> void:
|
func _init(agent: GSAISteeringAgent, zero_threshold := 0.001).(agent) -> void:
|
||||||
self.zero_threshold = zero_threshold
|
self.zero_threshold = zero_threshold
|
||||||
|
|
||||||
|
|
||||||
# Appends a steering behavior as a child of this container.
|
# Appends a steering behavior as a child of this container.
|
||||||
func add(behavior: GSTSteeringBehavior) -> void:
|
func add(behavior: GSAISteeringBehavior) -> void:
|
||||||
_behaviors.append(behavior)
|
_behaviors.append(behavior)
|
||||||
|
|
||||||
|
|
||||||
# Returns the behavior at the position in the pool referred to by `index`, or
|
# Returns the behavior at the position in the pool referred to by `index`, or
|
||||||
# `null` if no behavior was found.
|
# `null` if no behavior was found.
|
||||||
func get_behavior_at(index: int) -> GSTSteeringBehavior:
|
func get_behavior_at(index: int) -> GSAISteeringBehavior:
|
||||||
if _behaviors.size() > index:
|
if _behaviors.size() > index:
|
||||||
return _behaviors[index]
|
return _behaviors[index]
|
||||||
printerr("Tried to get index " + str(index) + " in array of size " + str(_behaviors.size()))
|
printerr("Tried to get index " + str(index) + " in array of size " + str(_behaviors.size()))
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(accel: GSTTargetAcceleration) -> void:
|
func _calculate_steering(accel: GSAITargetAcceleration) -> void:
|
||||||
var threshold_squared := zero_threshold * zero_threshold
|
var threshold_squared := zero_threshold * zero_threshold
|
||||||
|
|
||||||
last_selected_index = -1
|
last_selected_index = -1
|
||||||
@ -41,7 +41,7 @@ func _calculate_steering(accel: GSTTargetAcceleration) -> void:
|
|||||||
if size > 0:
|
if size > 0:
|
||||||
for i in range(size):
|
for i in range(size):
|
||||||
last_selected_index = i
|
last_selected_index = i
|
||||||
var behavior: GSTSteeringBehavior = _behaviors[i]
|
var behavior: GSAISteeringBehavior = _behaviors[i]
|
||||||
behavior.calculate_steering(accel)
|
behavior.calculate_steering(accel)
|
||||||
|
|
||||||
if accel.get_magnitude_squared() > threshold_squared:
|
if accel.get_magnitude_squared() > threshold_squared:
|
@ -1,25 +1,25 @@
|
|||||||
# Calculates an acceleration to make an agent intercept another based on the
|
# Calculates an acceleration to make an agent intercept another based on the
|
||||||
# target agent's movement.
|
# target agent's movement.
|
||||||
class_name GSTPursue
|
class_name GSAIPursue
|
||||||
extends GSTSteeringBehavior
|
extends GSAISteeringBehavior
|
||||||
|
|
||||||
|
|
||||||
# The target agent that the behavior is trying to intercept.
|
# The target agent that the behavior is trying to intercept.
|
||||||
var target: GSTSteeringAgent
|
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
|
||||||
# location.
|
# location.
|
||||||
var predict_time_max: float
|
var predict_time_max: float
|
||||||
|
|
||||||
|
|
||||||
func _init(
|
func _init(
|
||||||
agent: GSTSteeringAgent,
|
agent: GSAISteeringAgent,
|
||||||
target: GSTSteeringAgent,
|
target: GSAISteeringAgent,
|
||||||
predict_time_max := 1.0).(agent) -> void:
|
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
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
var target_position := target.position
|
var target_position := target.position
|
||||||
var distance_squared := (target_position - agent.position).length_squared()
|
var distance_squared := (target_position - agent.position).length_squared()
|
||||||
|
|
@ -1,18 +1,18 @@
|
|||||||
# Calculates an acceleration to take an agent to a target agent's position
|
# Calculates an acceleration to take an agent to a target agent's position
|
||||||
# directly.
|
# directly.
|
||||||
class_name GSTSeek
|
class_name GSAISeek
|
||||||
extends GSTSteeringBehavior
|
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: GSTAgentLocation
|
var target: GSAIAgentLocation
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent) -> void:
|
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent) -> void:
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> 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
|
@ -1,24 +1,24 @@
|
|||||||
# Calculates an acceleration that repels the agent from its neighbors in the
|
# Calculates an acceleration that repels the agent from its neighbors in the
|
||||||
# given `GSTProximity`.
|
# given `GSAIProximity`.
|
||||||
#
|
#
|
||||||
# The acceleration is an average based on all neighbors, multiplied by a
|
# 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
|
# strength decreasing by the inverse square law in relation to distance, and it
|
||||||
# accumulates.
|
# accumulates.
|
||||||
class_name GSTSeparation
|
class_name GSAISeparation
|
||||||
extends GSTGroupBehavior
|
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
|
||||||
|
|
||||||
var _acceleration: GSTTargetAcceleration
|
var _acceleration: GSAITargetAcceleration
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) -> void:
|
func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
acceleration.set_zero()
|
acceleration.set_zero()
|
||||||
self._acceleration = acceleration
|
self._acceleration = acceleration
|
||||||
proximity._find_neighbors(_callback)
|
proximity._find_neighbors(_callback)
|
||||||
@ -27,7 +27,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
|||||||
# Callback for the proximity to call when finding neighbors. Determines the amount of
|
# Callback for the proximity to call when finding neighbors. Determines the amount of
|
||||||
# acceleration that `neighbor` imposes based on its distance from the owner agent.
|
# acceleration that `neighbor` imposes based on its distance from the owner agent.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _report_neighbor(neighbor: GSTSteeringAgent) -> bool:
|
func _report_neighbor(neighbor: GSAISteeringAgent) -> bool:
|
||||||
var to_agent := agent.position - neighbor.position
|
var to_agent := agent.position - neighbor.position
|
||||||
|
|
||||||
var distance_squared := to_agent.length_squared()
|
var distance_squared := to_agent.length_squared()
|
@ -1,5 +1,5 @@
|
|||||||
# Represents an agent with only a location and an orientation.
|
# Represents an agent with only a location and an orientation.
|
||||||
class_name GSTAgentLocation
|
class_name GSAIAgentLocation
|
||||||
|
|
||||||
|
|
||||||
# The agent's position in space.
|
# The agent's position in space.
|
@ -1,20 +1,20 @@
|
|||||||
# Base type for group-based steering behaviors.
|
# Base type for group-based steering behaviors.
|
||||||
class_name GSTGroupBehavior
|
class_name GSAIGroupBehavior
|
||||||
extends GSTSteeringBehavior
|
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: GSTProximity
|
var proximity: GSAIProximity
|
||||||
|
|
||||||
var _callback := funcref(self, "_report_neighbor")
|
var _callback := funcref(self, "_report_neighbor")
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void:
|
func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent) -> void:
|
||||||
self.proximity = proximity
|
self.proximity = proximity
|
||||||
|
|
||||||
|
|
||||||
# Internal callback for the behavior to define whether or not a member is
|
# Internal callback for the behavior to define whether or not a member is
|
||||||
# relevant
|
# relevant
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func _report_neighbor(neighbor: GSTSteeringAgent) -> bool:
|
func _report_neighbor(neighbor: GSAISteeringAgent) -> bool:
|
||||||
return false
|
return false
|
@ -1,6 +1,6 @@
|
|||||||
# Represents a path made up of Vector3 waypoints, split into segments path
|
# Represents a path made up of Vector3 waypoints, split into segments path
|
||||||
# follow behaviors can use.
|
# follow behaviors can use.
|
||||||
class_name GSTPath
|
class_name GSAIPath
|
||||||
extends Reference
|
extends Reference
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ func create_path(waypoints: Array) -> void:
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
current = waypoints[0]
|
current = waypoints[0]
|
||||||
var segment := GSTSegment.new(previous, current)
|
var segment := GSAISegment.new(previous, current)
|
||||||
length += segment.length
|
length += segment.length
|
||||||
segment.cumulative_length = length
|
segment.cumulative_length = length
|
||||||
_segments.append(segment)
|
_segments.append(segment)
|
||||||
@ -52,9 +52,9 @@ func calculate_distance(agent_current_position: Vector3) -> float:
|
|||||||
if _segments.size() == 0:
|
if _segments.size() == 0:
|
||||||
return 0.0
|
return 0.0
|
||||||
var smallest_distance_squared: float = INF
|
var smallest_distance_squared: float = INF
|
||||||
var nearest_segment: GSTSegment
|
var nearest_segment: GSAISegment
|
||||||
for i in range(_segments.size()):
|
for i in range(_segments.size()):
|
||||||
var segment: GSTSegment = _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,
|
segment.end,
|
||||||
@ -83,9 +83,9 @@ func calculate_target_position(target_distance: float) -> Vector3:
|
|||||||
elif target_distance > length:
|
elif target_distance > length:
|
||||||
target_distance = fmod(target_distance, length)
|
target_distance = fmod(target_distance, length)
|
||||||
|
|
||||||
var desired_segment: GSTSegment
|
var desired_segment: GSAISegment
|
||||||
for i in range(_segments.size()):
|
for i in range(_segments.size()):
|
||||||
var segment: GSTSegment = _segments[i]
|
var segment: GSAISegment = _segments[i]
|
||||||
if segment.cumulative_length >= target_distance:
|
if segment.cumulative_length >= target_distance:
|
||||||
desired_segment = segment
|
desired_segment = segment
|
||||||
break
|
break
|
||||||
@ -121,7 +121,7 @@ func _calculate_point_segment_distance_squared(start: Vector3, end: Vector3, pos
|
|||||||
return _nearest_point_on_segment.distance_squared_to(position)
|
return _nearest_point_on_segment.distance_squared_to(position)
|
||||||
|
|
||||||
|
|
||||||
class GSTSegment:
|
class GSAISegment:
|
||||||
var begin: Vector3
|
var begin: Vector3
|
||||||
var end: Vector3
|
var end: Vector3
|
||||||
var length: float
|
var length: float
|
@ -1,9 +1,9 @@
|
|||||||
# Adds velocity, speed, and size data to `GSTAgentLocation`.
|
# Adds velocity, speed, and size data to `GSAIAgentLocation`.
|
||||||
#
|
#
|
||||||
# It is the character's responsibility to keep this information up to date for
|
# It is the character's responsibility to keep this information up to date for
|
||||||
# the steering toolkit to work correctly.
|
# the steering toolkit to work correctly.
|
||||||
extends GSTAgentLocation
|
extends GSAIAgentLocation
|
||||||
class_name GSTSteeringAgent
|
class_name GSAISteeringAgent
|
||||||
|
|
||||||
|
|
||||||
# The amount of velocity to be considered effectively not moving.
|
# The amount of velocity to be considered effectively not moving.
|
@ -5,26 +5,26 @@
|
|||||||
#
|
#
|
||||||
# The `calculate_steering` function is the entry point for all behaviors.
|
# The `calculate_steering` function is the entry point for all behaviors.
|
||||||
# Individual steering behaviors encapsulate the steering logic.
|
# Individual steering behaviors encapsulate the steering logic.
|
||||||
class_name GSTSteeringBehavior
|
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.
|
||||||
var agent: GSTSteeringAgent
|
var agent: GSAISteeringAgent
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent) -> void:
|
func _init(agent: GSAISteeringAgent) -> void:
|
||||||
self.agent = agent
|
self.agent = agent
|
||||||
|
|
||||||
|
|
||||||
# Sets the `acceleration` with the behavior's desired amount of acceleration.
|
# Sets the `acceleration` with the behavior's desired amount of acceleration.
|
||||||
func calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
if is_enabled:
|
if is_enabled:
|
||||||
_calculate_steering(acceleration)
|
_calculate_steering(acceleration)
|
||||||
else:
|
else:
|
||||||
acceleration.set_zero()
|
acceleration.set_zero()
|
||||||
|
|
||||||
|
|
||||||
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
||||||
acceleration.set_zero()
|
acceleration.set_zero()
|
@ -1,6 +1,6 @@
|
|||||||
# A desired linear and angular amount of acceleration requested by the steering
|
# A desired linear and angular amount of acceleration requested by the steering
|
||||||
# system.
|
# system.
|
||||||
class_name GSTTargetAcceleration
|
class_name GSAITargetAcceleration
|
||||||
|
|
||||||
|
|
||||||
# Linear acceleration
|
# Linear acceleration
|
||||||
@ -18,7 +18,7 @@ func set_zero() -> void:
|
|||||||
|
|
||||||
|
|
||||||
# Adds `accel`'s components, multiplied by `scalar`, to this one.
|
# Adds `accel`'s components, multiplied by `scalar`, to this one.
|
||||||
func add_scaled_accel(accel: GSTTargetAcceleration, scalar: float) -> void:
|
func add_scaled_accel(accel: GSAITargetAcceleration, scalar: float) -> void:
|
||||||
linear += accel.linear * scalar
|
linear += accel.linear * scalar
|
||||||
angular += accel.angular * scalar
|
angular += accel.angular * scalar
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
# Math and vector utility functions.
|
# Math and vector utility functions.
|
||||||
class_name GSTUtils
|
class_name GSAIUtils
|
||||||
|
|
||||||
|
|
||||||
# Returns the `vector` with its length capped to `limit`.
|
# Returns the `vector` with its length capped to `limit`.
|
@ -1,10 +1,10 @@
|
|||||||
# Determines any agent that is in the specified list as being neighbors with the
|
# Determines any agent that is in the specified list as being neighbors with the
|
||||||
# owner agent, regardless of distance.
|
# owner agent, regardless of distance.
|
||||||
extends GSTProximity
|
extends GSAIProximity
|
||||||
class_name GSTInfiniteProximity
|
class_name GSAIInfiniteProximity
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, agents: Array).(agent, agents) -> void:
|
func _init(agent: GSAISteeringAgent, agents: Array).(agent, agents) -> void:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ func _find_neighbors(callback: FuncRef) -> int:
|
|||||||
var neighbor_count := 0
|
var neighbor_count := 0
|
||||||
var agent_count := agents.size()
|
var agent_count := agents.size()
|
||||||
for i in range(agent_count):
|
for i in range(agent_count):
|
||||||
var current_agent := agents[i] as GSTSteeringAgent
|
var current_agent := agents[i] as GSAISteeringAgent
|
||||||
|
|
||||||
if current_agent != agent:
|
if current_agent != agent:
|
||||||
if callback.call_func(current_agent):
|
if callback.call_func(current_agent):
|
@ -1,15 +1,15 @@
|
|||||||
# Base container type that stores data to find the neighbors of an agent.
|
# Base container type that stores data to find the neighbors of an agent.
|
||||||
extends Reference
|
extends Reference
|
||||||
class_name GSTProximity
|
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: GSTSteeringAgent
|
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
|
||||||
var agents := []
|
var agents := []
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, agents: Array) -> void:
|
func _init(agent: GSAISteeringAgent, agents: Array) -> void:
|
||||||
self.agent = agent
|
self.agent = agent
|
||||||
self.agents = agents
|
self.agents = agents
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
# Determines any agent that is in the specified list as being neighbors with the owner agent if
|
# Determines any agent that is in the specified list as being neighbors with the owner agent if
|
||||||
# they lie within the specified radius.
|
# they lie within the specified radius.
|
||||||
extends GSTProximity
|
extends GSAIProximity
|
||||||
class_name GSTRadiusProximity
|
class_name GSAIRadiusProximity
|
||||||
|
|
||||||
|
|
||||||
# The radius around the owning agent to find neighbors in
|
# The radius around the owning agent to find neighbors in
|
||||||
@ -11,7 +11,7 @@ var _last_frame := 0
|
|||||||
var _scene_tree: SceneTree
|
var _scene_tree: SceneTree
|
||||||
|
|
||||||
|
|
||||||
func _init(agent: GSTSteeringAgent, agents: Array, radius: float).(agent, agents) -> void:
|
func _init(agent: GSAISteeringAgent, agents: Array, radius: float).(agent, agents) -> void:
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
_scene_tree = Engine.get_main_loop()
|
_scene_tree = Engine.get_main_loop()
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func _find_neighbors(callback: FuncRef) -> int:
|
|||||||
var owner_position := agent.position
|
var owner_position := agent.position
|
||||||
|
|
||||||
for i in range(agent_count):
|
for i in range(agent_count):
|
||||||
var current_agent := agents[i] as GSTSteeringAgent
|
var current_agent := agents[i] as GSAISteeringAgent
|
||||||
|
|
||||||
if current_agent != agent:
|
if current_agent != agent:
|
||||||
var distance_squared := owner_position.distance_squared_to(current_agent.position)
|
var distance_squared := owner_position.distance_squared_to(current_agent.position)
|
||||||
@ -48,7 +48,7 @@ func _find_neighbors(callback: FuncRef) -> int:
|
|||||||
current_agent.is_tagged = false
|
current_agent.is_tagged = false
|
||||||
else:
|
else:
|
||||||
for i in range(agent_count):
|
for i in range(agent_count):
|
||||||
var current_agent = agents[i] as GSTSteeringAgent
|
var current_agent = agents[i] as GSAISteeringAgent
|
||||||
|
|
||||||
if current_agent != agent and current_agent.is_tagged:
|
if current_agent != agent and current_agent.is_tagged:
|
||||||
if callback.call_func(current_agent):
|
if callback.call_func(current_agent):
|
Loading…
Reference in New Issue
Block a user