2020-01-15 20:42:24 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
|
2020-01-22 17:55:49 +01:00
|
|
|
var _velocity := Vector2.ZERO
|
2020-02-11 18:33:25 +01:00
|
|
|
var _accel := GSAITargetAcceleration.new()
|
2020-01-22 17:55:49 +01:00
|
|
|
var _valid := false
|
|
|
|
var _drag := 0.1
|
|
|
|
|
2020-02-07 16:08:45 +01:00
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
onready var agent := GSAIKinematicBody2DAgent.new(self)
|
|
|
|
onready var path := GSAIPath.new([
|
2020-01-15 20:42:24 +01:00
|
|
|
Vector3(global_position.x, global_position.y, 0),
|
|
|
|
Vector3(global_position.x, global_position.y, 0)
|
|
|
|
], true)
|
2020-02-11 18:33:25 +01:00
|
|
|
onready var follow := GSAIFollowPath.new(agent, path, 0, 0)
|
2020-01-15 20:42:24 +01:00
|
|
|
|
|
|
|
|
2020-01-16 18:31:02 +01:00
|
|
|
func setup(
|
|
|
|
path_offset: float,
|
|
|
|
predict_time: float,
|
2020-01-22 17:55:49 +01:00
|
|
|
accel_max: float,
|
|
|
|
speed_max: float,
|
2020-01-16 18:31:02 +01:00
|
|
|
decel_radius: float,
|
|
|
|
arrival_tolerance: float
|
|
|
|
) -> void:
|
2020-01-15 20:42:24 +01:00
|
|
|
owner.drawer.connect("path_established", self, "_on_Drawer_path_established")
|
2020-01-16 18:31:02 +01:00
|
|
|
follow.path_offset = path_offset
|
|
|
|
follow.prediction_time = predict_time
|
|
|
|
follow.deceleration_radius = decel_radius
|
|
|
|
follow.arrival_tolerance = arrival_tolerance
|
2020-02-06 20:54:12 +01:00
|
|
|
|
|
|
|
agent.linear_acceleration_max = accel_max
|
|
|
|
agent.linear_speed_max = speed_max
|
|
|
|
agent.linear_drag_percentage = _drag
|
2020-01-15 20:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if _valid:
|
2020-02-06 20:46:21 +01:00
|
|
|
follow.calculate_steering(_accel)
|
2020-02-07 15:15:03 +01:00
|
|
|
agent._apply_steering(_accel, delta)
|
2020-01-15 20:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _on_Drawer_path_established(points: Array) -> void:
|
2020-02-07 16:08:45 +01:00
|
|
|
var positions := PoolVector3Array()
|
2020-01-15 20:42:24 +01:00
|
|
|
for p in points:
|
2020-02-07 16:08:45 +01:00
|
|
|
positions.append(Vector3(p.x, p.y, 0))
|
|
|
|
path.create_path(positions)
|
2020-01-15 20:42:24 +01:00
|
|
|
_valid = true
|