-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathnavigation_arena.gd
38 lines (26 loc) · 1.27 KB
/
navigation_arena.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extends Node3D
const Beetle = preload("beetle_move_to_position.gd")
@onready var camera_3d: Camera3D = %Camera3D
@onready var ray_cast_3d: RayCast3D = %RayCast3D
@onready var sphere: MeshInstance3D = %Sphere
@onready var beetle: Beetle = %Beetle
@onready var beetle_navigation_agent : NavigationAgent3D = beetle._navigation_agent
@onready var avoidance_toggle: CheckButton = %AvoidanceToggle
@onready var radius_slide: HSlider = %RadiusSlider
@onready var line = %Line
func _ready():
beetle_navigation_agent.connect("path_changed", _on_path_changed)
avoidance_toggle.toggled.connect(_on_avoidance_toggled)
radius_slide.value_changed.connect(_on_radius_value_changed)
func _on_path_changed():
line.create_line(beetle_navigation_agent.get_current_navigation_path())
func _on_avoidance_toggled(toggled: bool) -> void:
beetle.set_avoidance_enabled(toggled)
func _on_radius_value_changed(value: float) -> void:
beetle.set_avoidance_radius(value)
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
ray_cast_3d.target_position = camera_3d.project_ray_normal(get_viewport().get_mouse_position()) * 100.0
if ray_cast_3d.is_colliding():
sphere.global_position = ray_cast_3d.get_collision_point()
beetle.target_global_position = sphere.global_position