Skip to content

Commit f180a7b

Browse files
committed
Making navmesh work
1 parent a7c5721 commit f180a7b

22 files changed

+524
-184
lines changed

SceneManager/global_mesh.tscn

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
render_priority = 0
88
shader = ExtResource("2_14e8y")
99

10-
[node name="SceneAnchor" type="StaticBody3D" groups=["navmesh_generation_mesh"]]
10+
[node name="SceneAnchor" type="StaticBody3D" groups=["navmesh_generation_shape"]]
1111
script = ExtResource("1_b8vna")
1212
material = SubResource("ShaderMaterial_y2giy")

assets/images/z.png

8.2 KB
Loading

assets/images/z.png.import

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://dcmkq5hitdvrk"
6+
path.s3tc="res://.godot/imported/z.png-86b09e6c89ddedc872fecb164cadd780.s3tc.ctex"
7+
path.etc2="res://.godot/imported/z.png-86b09e6c89ddedc872fecb164cadd780.etc2.ctex"
8+
metadata={
9+
"imported_formats": ["s3tc_bptc", "etc2_astc"],
10+
"vram_texture": true
11+
}
12+
13+
[deps]
14+
15+
source_file="res://assets/images/z.png"
16+
dest_files=["res://.godot/imported/z.png-86b09e6c89ddedc872fecb164cadd780.s3tc.ctex", "res://.godot/imported/z.png-86b09e6c89ddedc872fecb164cadd780.etc2.ctex"]
17+
18+
[params]
19+
20+
compress/mode=2
21+
compress/high_quality=false
22+
compress/lossy_quality=0.7
23+
compress/hdr_compression=1
24+
compress/normal_map=0
25+
compress/channel_pack=0
26+
mipmaps/generate=true
27+
mipmaps/limit=-1
28+
roughness/mode=0
29+
roughness/src_normal=""
30+
process/fix_alpha_border=true
31+
process/premult_alpha=false
32+
process/normal_map_invert_y=false
33+
process/hdr_as_srgb=false
34+
process/hdr_clamp_exposure=false
35+
process/size_limit=0
36+
detect_3d/compress_to=0

export_presets.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ custom_features=""
99
export_filter="all_resources"
1010
include_filter=""
1111
exclude_filter=""
12-
export_path=""
12+
export_path="../exports/GodotToy.apk"
1313
encryption_include_filters=""
1414
encryption_exclude_filters=""
1515
encrypt_pck=false

godot_plushie/godot_plushie.gd

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
extends PickableCharacterBody3D
22
class_name GodotPlushie
33

4-
@export var movement_speed:float = 5.0
54
@onready var navigation_agent_3d = %NavigationAgent3D
6-
@export var can_pathfind_navigate:bool = true
5+
@export var can_pathfind_navigate : bool = false
6+
77
func _ready():
88
navigation_agent_3d.velocity_computed.connect(_on_navigation_velocity_computed)
99

10-
func set_navigation_target(navigation_target: Vector3):
11-
navigation_agent_3d.set_target_position(navigation_target)
1210

1311
# Unfreeze is called by our main script once our global mesh is setup.
1412
func unfreeze():
15-
print("Unfreeze plushie")
16-
1713
super()
1814

1915
$StateMachine.state = $StateMachine/FallingState
2016

2117

2218
func pick_up(pick_up_by):
23-
print("Pickup plushie")
24-
2519
if is_frozen:
2620
return
2721

@@ -31,27 +25,20 @@ func pick_up(pick_up_by):
3125

3226

3327
func let_go(new_linear_velocity = Vector3()):
34-
print("Let go plushie")
3528
if not picked_up_by:
3629
return
3730

3831
super(new_linear_velocity)
3932

4033
$StateMachine.state = $StateMachine/FallingState
4134

42-
func _physics_process(delta):
43-
if can_pathfind_navigate and not navigation_agent_3d.is_navigation_finished():
44-
var next_path_position: Vector3 = navigation_agent_3d.get_next_path_position()
45-
var new_velocity: Vector3 = global_position.direction_to(next_path_position) * movement_speed
46-
if navigation_agent_3d.avoidance_enabled:
47-
navigation_agent_3d.velocity = new_velocity
48-
else:
49-
_on_navigation_velocity_computed(new_velocity)
5035

36+
func _physics_process(delta):
5137
# Handle by state machine
5238
if $StateMachine.do_physics_process(delta):
5339
move_and_slide()
5440

41+
5542
func _on_navigation_velocity_computed(safe_velocity: Vector3):
5643
if can_pathfind_navigate:
5744
velocity = safe_velocity

godot_plushie/godot_plushie.tscn

+96-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
[gd_scene load_steps=13 format=3 uid="uid://5b1fwnd8pyyc"]
1+
[gd_scene load_steps=26 format=3 uid="uid://5b1fwnd8pyyc"]
22

33
[ext_resource type="Script" path="res://godot_plushie/godot_plushie.gd" id="1_7ltfj"]
44
[ext_resource type="Shader" path="res://materials/highlight_by_normal.gdshader" id="2_drmmc"]
55
[ext_resource type="PackedScene" uid="uid://4qv1ic25pm3g" path="res://godot_plushie/plushie_visual_only.tscn" id="3_nbn1n"]
6+
[ext_resource type="Script" path="res://godot_plushie/plushie_detector.gd" id="4_salng"]
67
[ext_resource type="Script" path="res://godot_plushie/statemachine/statemachine.gd" id="5_nl81g"]
7-
[ext_resource type="Script" path="res://godot_plushie/idle_state.gd" id="6_3onee"]
8-
[ext_resource type="Script" path="res://godot_plushie/frozen_state.gd" id="7_7d5w8"]
9-
[ext_resource type="Script" path="res://godot_plushie/falling_state.gd" id="7_s0i25"]
10-
[ext_resource type="Script" path="res://godot_plushie/picked_up_state.gd" id="9_lh4d6"]
11-
[ext_resource type="Script" path="res://godot_plushie/jumping_for_food_state.gd" id="9_n6vq4"]
8+
[ext_resource type="Script" path="res://godot_plushie/statemachine/states/idle_state.gd" id="6_3onee"]
9+
[ext_resource type="Script" path="res://godot_plushie/statemachine/states/frozen_state.gd" id="7_7d5w8"]
10+
[ext_resource type="Script" path="res://godot_plushie/statemachine/states/falling_state.gd" id="7_s0i25"]
11+
[ext_resource type="Script" path="res://godot_plushie/statemachine/states/picked_up_state.gd" id="9_lh4d6"]
12+
[ext_resource type="Script" path="res://godot_plushie/statemachine/states/jumping_for_food_state.gd" id="9_n6vq4"]
13+
[ext_resource type="Script" path="res://godot_plushie/statemachine/states/move_to_state.gd" id="10_2lf8p"]
14+
[ext_resource type="Script" path="res://godot_plushie/sad_state.gd" id="12_36y4b"]
15+
[ext_resource type="Script" path="res://godot_plushie/sleep_state.gd" id="13_nkr01"]
16+
[ext_resource type="Texture2D" uid="uid://dcmkq5hitdvrk" path="res://assets/images/z.png" id="14_1oi5n"]
1217

1318
[sub_resource type="ShaderMaterial" id="ShaderMaterial_jl0g4"]
1419
render_priority = 0
@@ -19,38 +24,87 @@ shader_parameter/specular = 0.5
1924
shader_parameter/metallic = null
2025
shader_parameter/roughness = 1.0
2126

22-
[sub_resource type="BoxShape3D" id="BoxShape3D_x2ken"]
23-
size = Vector3(0.1, 0.15, 0.1)
27+
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_224wo"]
28+
margin = 0.01
29+
radius = 0.05
30+
height = 0.15
31+
32+
[sub_resource type="SphereShape3D" id="SphereShape3D_grwlp"]
33+
radius = 0.0770797
2434

2535
[sub_resource type="SphereShape3D" id="SphereShape3D_5vt2m"]
26-
radius = 0.3
36+
radius = 0.2
37+
38+
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_2a3mu"]
39+
transparency = 1
40+
shading_mode = 0
41+
albedo_texture = ExtResource("14_1oi5n")
42+
billboard_mode = 3
43+
billboard_keep_scale = true
44+
particles_anim_h_frames = 1
45+
particles_anim_v_frames = 1
46+
particles_anim_loop = false
47+
48+
[sub_resource type="Curve" id="Curve_dpdwo"]
49+
_data = [Vector2(0, 0.978022), 0.0, 0.0, 0, 0, Vector2(1, 0.120879), -3.01099, 0.0, 0, 0]
50+
point_count = 2
51+
52+
[sub_resource type="CurveTexture" id="CurveTexture_ol181"]
53+
curve = SubResource("Curve_dpdwo")
54+
55+
[sub_resource type="Curve" id="Curve_lvtns"]
56+
_data = [Vector2(0, 0.252747), 0.0, 5.1617, 0, 0, Vector2(0.233577, 1), 4.66619e-07, 4.66619e-07, 0, 0, Vector2(1, 0), -2.39108, 0.0, 0, 0]
57+
point_count = 3
58+
59+
[sub_resource type="CurveTexture" id="CurveTexture_ntjny"]
60+
curve = SubResource("Curve_lvtns")
61+
62+
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_c7eyl"]
63+
gravity = Vector3(0, 0.1, 0)
64+
scale_curve = SubResource("CurveTexture_ntjny")
65+
alpha_curve = SubResource("CurveTexture_ol181")
66+
turbulence_enabled = true
67+
turbulence_noise_scale = 6.045
68+
69+
[sub_resource type="QuadMesh" id="QuadMesh_el381"]
70+
size = Vector2(0.05, 0.05)
2771

2872
[node name="GodotPlushie" type="CharacterBody3D" groups=["unfreeze_on_start"]]
2973
script = ExtResource("1_7ltfj")
3074
snap_on_pickup = false
3175
highlight_material = SubResource("ShaderMaterial_jl0g4")
3276

33-
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
77+
[node name="GroundCollision" type="CollisionShape3D" parent="."]
3478
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.075, 0)
35-
shape = SubResource("BoxShape3D_x2ken")
79+
shape = SubResource("CapsuleShape3D_224wo")
80+
81+
[node name="HeadCollision" type="CollisionShape3D" parent="."]
82+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0869923, 0)
83+
shape = SubResource("SphereShape3D_grwlp")
3684

3785
[node name="Plushie" parent="." instance=ExtResource("3_nbn1n")]
3886

39-
[node name="FoodDetector" type="Area3D" parent="."]
87+
[node name="PlushieDetector" type="Area3D" parent="."]
4088
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0)
4189
collision_layer = 2
4290
collision_mask = 2
91+
script = ExtResource("4_salng")
4392

44-
[node name="CollisionShape3D" type="CollisionShape3D" parent="FoodDetector"]
93+
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlushieDetector"]
4594
shape = SubResource("SphereShape3D_5vt2m")
4695

47-
[node name="StateMachine" type="Node3D" parent="." node_paths=PackedStringArray("state")]
96+
[node name="StateMachine" type="Node3D" parent="." node_paths=PackedStringArray("plushie", "animator", "navigation_agent", "plushie_detector", "state")]
4897
script = ExtResource("5_nl81g")
98+
plushie = NodePath("..")
99+
animator = NodePath("../Plushie")
100+
navigation_agent = NodePath("../NavigationAgent3D")
101+
plushie_detector = NodePath("../PlushieDetector")
49102
state = NodePath("FrozenState")
50103

51104
[node name="StateLabel" type="Label3D" parent="StateMachine"]
52105
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.191594, 0)
53-
pixel_size = 0.002
106+
visible = false
107+
pixel_size = 0.001
54108
text = "Hello"
55109
vertical_alignment = 2
56110

@@ -69,5 +123,32 @@ script = ExtResource("9_lh4d6")
69123
[node name="JumpingForFoodState" type="Node3D" parent="StateMachine"]
70124
script = ExtResource("9_n6vq4")
71125

126+
[node name="MoveToState" type="Node3D" parent="StateMachine"]
127+
script = ExtResource("10_2lf8p")
128+
129+
[node name="From" type="Node3D" parent="StateMachine/MoveToState"]
130+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0.07)
131+
132+
[node name="To" type="Node3D" parent="StateMachine/MoveToState"]
133+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, 0.07)
134+
135+
[node name="SadState" type="Node3D" parent="StateMachine"]
136+
script = ExtResource("12_36y4b")
137+
138+
[node name="SleepState" type="Node3D" parent="StateMachine"]
139+
script = ExtResource("13_nkr01")
140+
141+
[node name="GPUParticles3D" type="GPUParticles3D" parent="StateMachine/SleepState"]
142+
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0643394, 0.0959583)
143+
material_override = SubResource("StandardMaterial3D_2a3mu")
144+
emitting = false
145+
amount = 3
146+
lifetime = 2.0
147+
process_material = SubResource("ParticleProcessMaterial_c7eyl")
148+
draw_pass_1 = SubResource("QuadMesh_el381")
149+
72150
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="."]
73151
unique_name_in_owner = true
152+
path_desired_distance = 0.1
153+
target_desired_distance = 0.1
154+
path_max_distance = 1.01

godot_plushie/idle_state.gd

-41
This file was deleted.

godot_plushie/jumping_for_food_state.gd

-51
This file was deleted.

godot_plushie/plushie_detector.gd

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
extends Area3D
2+
class_name PlushieDetector
3+
4+
5+
func has_food() -> bool:
6+
for collision_object : CollisionObject3D in get_overlapping_bodies():
7+
if collision_object.collision_layer & 2:
8+
return true
9+
return false
10+
11+
12+
func get_food() -> Array[PickableRigidBody3D]:
13+
var result : Array[PickableRigidBody3D]
14+
for collision_object : CollisionObject3D in get_overlapping_bodies():
15+
if collision_object is PickableRigidBody3D and collision_object.collision_layer & 2:
16+
var food : PickableRigidBody3D = collision_object
17+
if food:
18+
result.push_back(food)
19+
20+
return result

0 commit comments

Comments
 (0)