2020-08-23 18:25:09 +02:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
|
|
|
var player_agent: GSAIAgentLocation
|
|
|
|
var velocity := Vector2.ZERO
|
|
|
|
var start_speed: float
|
|
|
|
var start_accel: float
|
|
|
|
var use_seek := true
|
|
|
|
|
2023-01-13 19:42:14 +01:00
|
|
|
var agent : GSAIKinematicBody2DAgent = null
|
|
|
|
var accel : GSAITargetAcceleration = null
|
|
|
|
var seek : GSAISeek = null
|
|
|
|
var flee : GSAIFlee = null
|
2020-08-23 18:25:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2023-01-13 19:42:14 +01:00
|
|
|
agent = GSAIKinematicBody2DAgent.new()
|
|
|
|
agent.body = self
|
|
|
|
|
|
|
|
accel = GSAITargetAcceleration.new()
|
|
|
|
|
|
|
|
seek = GSAISeek.new()
|
|
|
|
seek.agent = agent
|
|
|
|
seek.target = player_agent
|
|
|
|
|
|
|
|
flee = GSAIFlee.new()
|
|
|
|
flee.agent = agent
|
|
|
|
flee.target = player_agent
|
|
|
|
|
2020-08-23 18:25:09 +02:00
|
|
|
agent.linear_acceleration_max = start_accel
|
|
|
|
agent.linear_speed_max = start_speed
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
if not player_agent:
|
|
|
|
return
|
|
|
|
|
|
|
|
if use_seek:
|
|
|
|
seek.calculate_steering(accel)
|
|
|
|
else:
|
|
|
|
flee.calculate_steering(accel)
|
|
|
|
|
|
|
|
agent._apply_steering(accel, delta)
|