Skip to content

Commit

Permalink
hide obstacle avoidance UI
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquelalves committed Feb 28, 2023
1 parent 99f3888 commit 2b988c3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 52 deletions.
3 changes: 2 additions & 1 deletion navigation/beetle.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ transform = Transform3D(-1.4, 0, -2.11394e-07, 0, 1.4, 0, 2.11394e-07, 0, -1.4,

[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
unique_name_in_owner = true
path_desired_distance = 0.2
target_desired_distance = 0.2
agent_height_offset = 0.5
avoidance_enabled = true
radius = 1.0
time_horizon = 0.5
debug_enabled = true
20 changes: 16 additions & 4 deletions navigation/beetle_move_to_position.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ func _ready() -> void:
set_physics_process(false)


func set_avoidance_enabled(enabled: bool) -> void:
_navigation_agent.avoidance_enabled = enabled


func set_avoidance_radius(radius: float) -> void:
_navigation_agent.radius = radius


func _physics_process(_delta: float) -> void:
# Wait for the next location to be accessible, for example, a moving platform.
var next_location := _navigation_agent.get_next_path_position()

# var global_look_position: Vector3 = target_global_position
# global_look_position.y = global_position.y
look_at(next_location)

var direction := (next_location - global_position).normalized()
_navigation_agent.set_velocity(direction * SPEED)

if _navigation_agent.avoidance_enabled:
_navigation_agent.set_velocity(direction * SPEED)
else:
velocity = direction * SPEED
move_and_slide()

if _navigation_agent.is_navigation_finished():
_beetle_skin.idle()
set_physics_process(false)
Expand Down
1 change: 0 additions & 1 deletion navigation/beetle_moving_platforms.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extends CharacterBody3D

signal path_end_reached


const SPEED := 3.0

## This array represents a queue of the locations the agent will move towards.
Expand Down
15 changes: 15 additions & 0 deletions navigation/navigation_arena.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ const Beetle = preload("beetle_move_to_position.gd")
@onready var ray_cast_3d: RayCast3D = %RayCast3D
@onready var sphere: MeshInstance3D = %Sphere
@onready var beetle: Beetle = %Beetle
@onready var avoidance_toggle: CheckButton = %AvoidanceToggle
@onready var radius_slide: HSlider = %RadiusSlider


func _ready():
avoidance_toggle.toggled.connect(_on_avoidance_toggled)
radius_slide.value_changed.connect(_on_radius_value_changed)


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:
Expand Down
55 changes: 52 additions & 3 deletions navigation/navigation_arena.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[ext_resource type="Script" path="res://navigation/beetle_move_to_position.gd" id="3_g41jl"]
[ext_resource type="Sky" uid="uid://jonn5eom7asv" path="res://outdoor_environment/sky/blue_sky.tres" id="5_qta1r"]
[ext_resource type="Shader" path="res://outdoor_environment/materials/water/water_shader.gdshader" id="6_luajm"]
[ext_resource type="PackedScene" uid="uid://c0qm7kpfs8hcr" path="res://navigation/obstacle.tscn" id="7_a3on2"]
[ext_resource type="Theme" uid="uid://bgpjrj0qf7awr" path="res://interface/theme.tres" id="7_vkmm1"]
[ext_resource type="Texture2D" uid="uid://ssrlnj65d4bs" path="res://outdoor_environment/materials/water/textures/caustic_texture.png" id="7_y1abr"]

[sub_resource type="NavigationMesh" id="NavigationMesh_f1mbg"]
Expand Down Expand Up @@ -148,5 +148,54 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.692534, 0)
material_override = SubResource("ShaderMaterial_e6agb")
mesh = SubResource("PlaneMesh_3tmkq")

[node name="Obstacle" parent="." instance=ExtResource("7_a3on2")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.71932, 0.95, 0.681051)
[node name="Panel" type="Panel" parent="."]
visible = false
offset_left = 28.0
offset_top = 29.0
offset_right = 354.0
offset_bottom = 145.0

[node name="AvoidanceSettings" type="MarginContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("7_vkmm1")

[node name="VBoxContainer" type="VBoxContainer" parent="Panel/AvoidanceSettings"]
layout_mode = 2

[node name="HBoxContainer" type="HBoxContainer" parent="Panel/AvoidanceSettings/VBoxContainer"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2

[node name="Label" type="Label" parent="Panel/AvoidanceSettings/VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Avoidance Toggle"

[node name="AvoidanceToggle" type="CheckButton" parent="Panel/AvoidanceSettings/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
button_pressed = true
flat = true

[node name="HBoxContainer2" type="HBoxContainer" parent="Panel/AvoidanceSettings/VBoxContainer"]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2

[node name="Label" type="Label" parent="Panel/AvoidanceSettings/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Avoidance Radius"

[node name="RadiusSlider" type="HSlider" parent="Panel/AvoidanceSettings/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
min_value = 0.1
max_value = 5.0
step = 0.1
value = 0.5
36 changes: 0 additions & 36 deletions navigation/obstacle.gd

This file was deleted.

64 changes: 57 additions & 7 deletions navigation/obstacle.tscn
Original file line number Diff line number Diff line change
@@ -1,16 +1,66 @@
[gd_scene load_steps=3 format=3 uid="uid://c0qm7kpfs8hcr"]

[ext_resource type="Script" path="res://navigation/obstacle.gd" id="1_obtb1"]
[gd_scene load_steps=7 format=3 uid="uid://8d4cudcb6xpc"]

[sub_resource type="SphereShape3D" id="SphereShape3D_id3s4"]

[node name="Obstacle" type="CharacterBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.28523, 0.95, -2.33882)
script = ExtResource("1_obtb1")
[sub_resource type="Animation" id="Animation_veodu"]
resource_name = "default"
length = 3.0
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 1.5),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0.0613372, 0.95, 2.19116), Vector3(0.0613372, 0.95, -1.37318)]
}

[sub_resource type="Animation" id="Animation_e4hp1"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0.0613372, 0.95, 2.19116)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_l5lp8"]
_data = {
"RESET": SubResource("Animation_e4hp1"),
"default": SubResource("Animation_veodu")
}

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rekvp"]
albedo_color = Color(1, 0, 0, 1)

[node name="CSGSphere3D" type="CSGSphere3D" parent="."]
[sub_resource type="SphereMesh" id="SphereMesh_reh6l"]

[node name="Obstacle" type="CharacterBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0613372, 0.95, 0.29285)

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_id3s4")

[node name="NavigationObstacle3D" type="NavigationObstacle3D" parent="."]
estimate_radius = false
radius = 0.5

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "default"
libraries = {
"": SubResource("AnimationLibrary_l5lp8")
}

[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
material_override = SubResource("StandardMaterial3D_rekvp")
mesh = SubResource("SphereMesh_reh6l")

0 comments on commit 2b988c3

Please sign in to comment.