2020-08-23 18:25:09 +02:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
2023-01-13 19:42:14 +01:00
|
|
|
var agent := GSAIKinematicBody2DAgent.new()
|
2020-08-23 18:25:09 +02:00
|
|
|
var target := GSAIAgentLocation.new()
|
2023-01-13 19:42:14 +01:00
|
|
|
var arrive := GSAIArrive.new()
|
2020-08-23 18:25:09 +02:00
|
|
|
var _accel := GSAITargetAcceleration.new()
|
|
|
|
|
|
|
|
var _velocity := Vector2()
|
|
|
|
var _drag := 0.1
|
|
|
|
|
2023-01-13 19:42:14 +01:00
|
|
|
func _init() -> void:
|
|
|
|
agent.body = self
|
|
|
|
arrive.agent = agent
|
|
|
|
arrive.target = target
|
2020-08-23 18:25:09 +02:00
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
arrive.calculate_steering(_accel)
|
|
|
|
agent._apply_steering(_accel, delta)
|
|
|
|
|
|
|
|
|
|
|
|
func setup(
|
|
|
|
linear_speed_max: float,
|
|
|
|
linear_acceleration_max: float,
|
|
|
|
arrival_tolerance: float,
|
|
|
|
deceleration_radius: float
|
|
|
|
) -> void:
|
|
|
|
agent.linear_speed_max = linear_speed_max
|
|
|
|
agent.linear_acceleration_max = linear_acceleration_max
|
|
|
|
agent.linear_drag_percentage = _drag
|
|
|
|
arrive.deceleration_radius = deceleration_radius
|
|
|
|
arrive.arrival_tolerance = arrival_tolerance
|
|
|
|
target.position = agent.position
|