2019-12-16 22:14:46 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
var player_agent: GSAIAgentLocation
|
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-11 18:33:25 +01:00
|
|
|
onready var agent := GSAIKinematicBody2DAgent.new(self)
|
|
|
|
onready var accel := GSAITargetAcceleration.new()
|
|
|
|
onready var seek := GSAISeek.new(agent, player_agent)
|
|
|
|
onready var flee := GSAIFlee.new(agent, player_agent)
|
2020-01-22 17:55:49 +01:00
|
|
|
|
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-02-14 17:35:18 +01:00
|
|
|
|
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)
|
2020-02-14 17:35:18 +01:00
|
|
|
|
2020-02-07 15:15:03 +01:00
|
|
|
agent._apply_steering(accel, delta)
|