2019-12-20 19:17:27 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
|
2019-12-23 17:38:27 +01:00
|
|
|
onready var collision_shape: = $CollisionShape2D
|
|
|
|
|
|
|
|
var _cannon: Rect2
|
|
|
|
|
|
|
|
var _agent: = GSTSteeringAgent.new()
|
|
|
|
var _accel: = GSTTargetAcceleration.new()
|
2019-12-20 19:17:27 +01:00
|
|
|
|
|
|
|
var _angular_velocity: = 0.0
|
2020-01-15 20:15:31 +01:00
|
|
|
var _angular_drag: = 0.01
|
2019-12-20 19:17:27 +01:00
|
|
|
var _face: GSTFace
|
|
|
|
|
|
|
|
|
2019-12-23 17:38:27 +01:00
|
|
|
func _ready() -> void:
|
2020-01-15 20:15:31 +01:00
|
|
|
var radius = collision_shape.shape.radius
|
|
|
|
_cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2))
|
2019-12-23 17:38:27 +01:00
|
|
|
|
|
|
|
|
2019-12-20 19:17:27 +01:00
|
|
|
func _draw() -> void:
|
|
|
|
draw_rect(_cannon, Color.blue)
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if not _face:
|
2019-12-22 20:08:53 +01:00
|
|
|
return
|
2019-12-20 19:17:27 +01:00
|
|
|
|
|
|
|
_accel = _face.calculate_steering(_accel)
|
|
|
|
_angular_velocity += _accel.angular
|
|
|
|
|
2020-01-15 20:15:31 +01:00
|
|
|
_angular_velocity = lerp(_angular_velocity, 0, _angular_drag)
|
2019-12-20 19:17:27 +01:00
|
|
|
|
|
|
|
rotation += _angular_velocity * delta
|
|
|
|
|
|
|
|
_update_agent()
|
|
|
|
|
|
|
|
|
2020-01-15 20:15:31 +01:00
|
|
|
func setup(
|
|
|
|
align_tolerance: float,
|
|
|
|
deceleration_radius: float,
|
|
|
|
max_angular_accel: float,
|
|
|
|
max_angular_speed: float
|
|
|
|
) -> void:
|
2019-12-20 19:17:27 +01:00
|
|
|
_face = GSTFace.new(_agent, owner.player.agent)
|
|
|
|
|
2020-01-15 20:15:31 +01:00
|
|
|
_face.alignment_tolerance = align_tolerance
|
|
|
|
_face.deceleration_radius = deceleration_radius
|
2019-12-20 19:17:27 +01:00
|
|
|
|
2020-01-15 20:15:31 +01:00
|
|
|
_agent.max_angular_acceleration = max_angular_accel
|
|
|
|
_agent.max_angular_speed = max_angular_speed
|
2019-12-20 19:17:27 +01:00
|
|
|
_agent.position = Vector3(global_position.x, global_position.y, 0)
|
|
|
|
|
|
|
|
_update_agent()
|
2019-12-22 20:08:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _update_agent() -> void:
|
|
|
|
_agent.angular_velocity = _angular_velocity
|
|
|
|
_agent.orientation = rotation
|