mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +01:00
parent
809b0c53df
commit
7241bc754b
@ -1,4 +1,4 @@
|
||||
extends Node2D
|
||||
extends Node
|
||||
|
||||
|
||||
export(float, 0, 2000, 40) var linear_speed_max := 800.0 setget set_linear_speed_max
|
||||
@ -6,12 +6,8 @@ export(float, 0, 200, 2.0) var linear_acceleration_max := 80.0 setget set_linear
|
||||
export(float, 0, 100, 0.1) var arrival_tolerance := 25.0 setget set_arrival_tolerance
|
||||
export(float, 0, 500, 10) var deceleration_radius := 125.0 setget set_deceleration_radius
|
||||
|
||||
const COLORS := {
|
||||
deceleration_radius = Color(1.0, 0.419, 0.592, 0.5),
|
||||
arrival_tolerance = Color(0.278, 0.231, 0.47, 0.3)
|
||||
}
|
||||
|
||||
onready var arriver := $Arriver
|
||||
onready var target_drawer := $TargetDrawer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@ -26,13 +22,7 @@ func _ready() -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.is_pressed():
|
||||
arriver.target.position = Vector3(event.position.x, event.position.y, 0)
|
||||
update()
|
||||
|
||||
|
||||
func _draw():
|
||||
var target_position := Vector2(arriver.target.position.x, arriver.target.position.y)
|
||||
draw_circle(target_position, deceleration_radius, COLORS.deceleration_radius)
|
||||
draw_circle(target_position, arrival_tolerance, COLORS.arrival_tolerance)
|
||||
target_drawer.update()
|
||||
|
||||
|
||||
func set_arrival_tolerance(value: float) -> void:
|
||||
|
@ -1,15 +1,16 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://demos/Arrive/Arriver.gd" type="Script" id=1]
|
||||
[ext_resource path="res://demos/Utils/DemoInterface.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://demos/Arrive/ArriveDemo.gd" type="Script" id=3]
|
||||
[ext_resource path="res://demos/Utils/BackgroudLayer.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://demos/Arrive/TargetDrawer.gd" type="Script" id=5]
|
||||
[ext_resource path="res://demos/Utils/CircleDraw.gd" type="Script" id=6]
|
||||
|
||||
[sub_resource type="CircleShape2D" id=1]
|
||||
radius = 16.0
|
||||
|
||||
[node name="ArriveDemo" type="Node2D"]
|
||||
[node name="ArriveDemo" type="Node"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="BackgroudLayer" parent="." instance=ExtResource( 4 )]
|
||||
@ -26,4 +27,9 @@ inner_color = Color( 0.235294, 0.639216, 0.439216, 1 )
|
||||
outer_color = Color( 0.560784, 0.870588, 0.364706, 1 )
|
||||
stroke = 4.0
|
||||
|
||||
[node name="TargetDrawer" type="Node2D" parent="."]
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="DemoInterface" parent="." instance=ExtResource( 2 )]
|
||||
text_bbcode = "Arrive Demo
|
||||
Mouse click to make the [color=lime]green \"Player\"[/color] move to the [color=fuchsia]purple target[/color]"
|
||||
|
20
project/demos/Arrive/TargetDrawer.gd
Normal file
20
project/demos/Arrive/TargetDrawer.gd
Normal file
@ -0,0 +1,20 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
const COLORS := {
|
||||
deceleration_radius = Color(1.0, 0.419, 0.592, 0.5),
|
||||
arrival_tolerance = Color(0.278, 0.231, 0.47, 0.3)
|
||||
}
|
||||
|
||||
var arriver: Node2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
yield(owner, "ready")
|
||||
arriver = owner.arriver
|
||||
|
||||
|
||||
func _draw():
|
||||
var target_position := GSTUtils.to_vector2(arriver.target.position)
|
||||
draw_circle(target_position, owner.deceleration_radius, COLORS.deceleration_radius)
|
||||
draw_circle(target_position, owner.arrival_tolerance, COLORS.arrival_tolerance)
|
Loading…
Reference in New Issue
Block a user