mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +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
30 lines
758 B
GDScript
30 lines
758 B
GDScript
extends KinematicBody2D
|
|
|
|
|
|
var agent := GSTNode2DAgent.new(self)
|
|
var target := GSTAgentLocation.new()
|
|
var arrive := GSTArrive.new(agent, target)
|
|
var _accel := GSTTargetAcceleration.new()
|
|
|
|
var _velocity := Vector2()
|
|
var _drag := 0.1
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
arrive.calculate_steering(_accel)
|
|
agent._apply_steering(_accel, delta)
|
|
|
|
|
|
func setup(
|
|
linear_speed_max: float,
|
|
linear_acceleration_max: float,
|
|
arrival_tolerance: float,
|
|
deceleration_radius: float
|
|
) -> void:
|
|
agent.linear_speed_max = linear_speed_max
|
|
agent.linear_acceleration_max = linear_acceleration_max
|
|
agent.linear_drag_percentage = _drag
|
|
arrive.deceleration_radius = deceleration_radius
|
|
arrive.arrival_tolerance = arrival_tolerance
|
|
target.position = agent.position
|