mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2025-01-05 17:59:39 +01:00
85784791ec
The agents auto-update themselves and can calculate their velocities. This keeps the user from having to create an update_agent function. It can also save the user from having to keep track of and update velocities at all by using the provided `apply_steering` method. Closes #15, closes #16
31 lines
673 B
GDScript
31 lines
673 B
GDScript
extends KinematicBody2D
|
|
|
|
|
|
var player_agent: GSTAgentLocation
|
|
var velocity := Vector2.ZERO
|
|
var start_speed: float
|
|
var start_accel: float
|
|
var use_seek := true
|
|
|
|
onready var agent := GSTNode2DAgent.new(self)
|
|
onready var accel := GSTTargetAcceleration.new()
|
|
onready var seek := GSTSeek.new(agent, player_agent)
|
|
onready var flee := GSTFlee.new(agent, player_agent)
|
|
|
|
|
|
func _ready() -> void:
|
|
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)
|