mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +01:00
6e6f27505c
The use of `not is_inside_tree()` before setting the setting class' value meant that the starting values would always be the default. Moving the value setting before checking for tree readiness fixes the issue.
47 lines
1.1 KiB
GDScript
47 lines
1.1 KiB
GDScript
extends KinematicBody2D
|
|
|
|
|
|
var face: GSTFace
|
|
var agent := GSTSteeringAgent.new()
|
|
|
|
var _accel := GSTTargetAcceleration.new()
|
|
var _angular_drag := 0.1
|
|
var _cannon: Rect2
|
|
|
|
onready var collision_shape := $CollisionShape2D
|
|
|
|
|
|
func _ready() -> void:
|
|
var radius = collision_shape.shape.radius
|
|
_cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius*2))
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
_accel = face.calculate_steering(_accel)
|
|
agent.angular_velocity += _accel.angular
|
|
agent.angular_velocity = lerp(agent.angular_velocity, 0, _angular_drag)
|
|
agent.orientation += agent.angular_velocity * delta
|
|
rotation = agent.orientation
|
|
|
|
|
|
func _draw() -> void:
|
|
draw_rect(_cannon, Color.cadetblue)
|
|
|
|
|
|
func setup(
|
|
player_agent: GSTAgentLocation,
|
|
align_tolerance: float,
|
|
deceleration_radius: float,
|
|
max_angular_accel: float,
|
|
max_angular_speed: float
|
|
) -> void:
|
|
face = GSTFace.new(agent, player_agent)
|
|
|
|
face.alignment_tolerance = align_tolerance
|
|
face.deceleration_radius = deceleration_radius
|
|
|
|
agent.max_angular_acceleration = max_angular_accel
|
|
agent.max_angular_speed = max_angular_speed
|
|
agent.position = Vector3(global_position.x, global_position.y, 0)
|
|
|