2019-12-16 22:14:46 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
|
2019-12-19 20:04:08 +01:00
|
|
|
var player_agent: GSTAgentLocation
|
2020-01-16 09:44:44 +01:00
|
|
|
var velocity := Vector2.ZERO
|
2020-01-13 18:38:46 +01:00
|
|
|
var start_speed: float
|
|
|
|
var start_accel: float
|
2020-01-16 09:44:44 +01:00
|
|
|
var use_seek := true
|
2019-12-16 22:14:46 +01:00
|
|
|
|
2020-02-06 22:29:48 +01:00
|
|
|
onready var agent := GSTKinematicBody2DAgent.new(self)
|
2020-01-22 17:55:49 +01:00
|
|
|
onready var accel := GSTTargetAcceleration.new()
|
|
|
|
onready var seek := GSTSeek.new(agent, player_agent)
|
|
|
|
onready var flee := GSTFlee.new(agent, player_agent)
|
|
|
|
|
2019-12-16 22:14:46 +01:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2020-01-22 17:55:49 +01:00
|
|
|
agent.linear_acceleration_max = start_accel
|
|
|
|
agent.linear_speed_max = start_speed
|
2019-12-16 22:14:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
2019-12-17 05:12:18 +01:00
|
|
|
if not player_agent:
|
|
|
|
return
|
|
|
|
|
2020-01-15 20:15:31 +01:00
|
|
|
if use_seek:
|
2020-02-06 20:46:21 +01:00
|
|
|
seek.calculate_steering(accel)
|
2020-01-15 20:15:31 +01:00
|
|
|
else:
|
2020-02-06 20:46:21 +01:00
|
|
|
flee.calculate_steering(accel)
|
2019-12-16 22:14:46 +01:00
|
|
|
|
2020-02-07 15:15:03 +01:00
|
|
|
agent._apply_steering(accel, delta)
|