2020-01-16 09:44:44 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
|
|
|
|
var agent := GSTSteeringAgent.new()
|
|
|
|
var target := GSTAgentLocation.new()
|
|
|
|
var arrive := GSTArrive.new(agent, target)
|
|
|
|
var _accel := GSTTargetAcceleration.new()
|
|
|
|
|
|
|
|
var _velocity := Vector2()
|
|
|
|
var _drag := 0.1
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
_update_agent()
|
|
|
|
_accel = arrive.calculate_steering(_accel)
|
|
|
|
_velocity += Vector2(_accel.linear.x, _accel.linear.y)
|
2020-01-22 17:55:49 +01:00
|
|
|
_velocity = _velocity.linear_interpolate(Vector2.ZERO, _drag).clamped(agent.linear_speed_max)
|
2020-01-16 09:44:44 +01:00
|
|
|
_velocity = move_and_slide(_velocity)
|
|
|
|
|
|
|
|
|
|
|
|
func setup(
|
2020-01-22 17:55:49 +01:00
|
|
|
linear_speed_max: float,
|
|
|
|
linear_acceleration_max: float,
|
2020-01-16 09:44:44 +01:00
|
|
|
arrival_tolerance: float,
|
|
|
|
deceleration_radius: float
|
|
|
|
) -> void:
|
2020-01-22 17:55:49 +01:00
|
|
|
agent.linear_speed_max = linear_speed_max
|
|
|
|
agent.linear_acceleration_max = linear_acceleration_max
|
2020-01-16 09:44:44 +01:00
|
|
|
agent.position = Vector3(global_position.x, global_position.y, 0)
|
|
|
|
arrive.deceleration_radius = deceleration_radius
|
|
|
|
arrive.arrival_tolerance = arrival_tolerance
|
|
|
|
target.position = agent.position
|
|
|
|
|
|
|
|
|
|
|
|
func _update_agent() -> void:
|
|
|
|
agent.position = Vector3(global_position.x, global_position.y, 0)
|
|
|
|
agent.linear_velocity = Vector3(_velocity.x, _velocity.y, 0)
|