2020-01-15 20:42:24 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
|
2020-01-22 17:55:49 +01:00
|
|
|
var _velocity := Vector2.ZERO
|
|
|
|
var _accel := GSTTargetAcceleration.new()
|
|
|
|
var _valid := false
|
|
|
|
var _drag := 0.1
|
|
|
|
|
2020-02-06 20:54:12 +01:00
|
|
|
onready var agent := GSTNode2DAgent.new(self)
|
2020-01-16 12:10:55 +01:00
|
|
|
onready var path := GSTPath.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-01-16 18:31:02 +01:00
|
|
|
onready var follow := GSTFollowPath.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-06 20:54:12 +01:00
|
|
|
agent._apply_steering(_accel, delta)
|
2020-01-15 20:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _on_Drawer_path_established(points: Array) -> void:
|
2020-01-16 12:10:55 +01:00
|
|
|
var points3 := []
|
2020-01-15 20:42:24 +01:00
|
|
|
for p in points:
|
|
|
|
points3.append(Vector3(p.x, p.y, 0))
|
|
|
|
path.create_path(points3)
|
|
|
|
_valid = true
|