From 7da59523a7c6fc4b65bf304addc0e5e1250093a3 Mon Sep 17 00:00:00 2001 From: Nikolai Fesenko <152747946+NikolaiFesenko-code@users.noreply.github.com> Date: Fri, 15 Aug 2025 15:26:47 +0200 Subject: [PATCH] person added start position --- Scenes/Prefabs/Person.tscn | 19 ++++++++++++++----- Scenes/Prefabs/cart.tscn | 2 +- Scenes/main.tscn | 2 +- Scripts/person.gd | 23 +++++++++++++++++++++++ Shaders/shirt.gdshader | 16 ++++++++++++++++ Shaders/shirt.gdshader.uid | 1 + 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 Shaders/shirt.gdshader create mode 100644 Shaders/shirt.gdshader.uid diff --git a/Scenes/Prefabs/Person.tscn b/Scenes/Prefabs/Person.tscn index ae7eda1..6d3532e 100644 --- a/Scenes/Prefabs/Person.tscn +++ b/Scenes/Prefabs/Person.tscn @@ -1,22 +1,31 @@ -[gd_scene load_steps=4 format=3 uid="uid://dqrqq5vg8hek3"] +[gd_scene load_steps=6 format=3 uid="uid://dqrqq5vg8hek3"] [ext_resource type="ArrayMesh" uid="uid://dwd6ylq5xn6kj" path="res://Blends/Person/Person.obj" id="1_11yxf"] [ext_resource type="Script" uid="uid://d308e5vxshc06" path="res://Scripts/person.gd" id="1_dh77o"] +[ext_resource type="Shader" uid="uid://bm15rdsdxldwl" path="res://Shaders/shirt.gdshader" id="3_dbviw"] -[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_dh77o"] +[sub_resource type="ShaderMaterial" id="ShaderMaterial_kmh38"] +render_priority = 0 +shader = ExtResource("3_dbviw") +shader_parameter/shirt_color = Vector3(0, 0, 0) + +[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_dbviw"] points = PackedVector3Array(0.465296, 4.41226, 2.90193, 0.333481, 5.90986, 1.44973, -0.46535, 4.41226, 2.90193, 0.465296, 2.1221, 2.90193, 0.88668, -1.00046, 1.81769, 0.465296, 4.41226, -1.76192, 0.333481, 5.90986, -0.25128, -0.333667, 5.90986, 1.44973, -0.46535, 4.41226, -1.76192, -0.46535, 2.1221, 2.90193, 0.88668, -1.35832, 1.81769, 0.88668, -1.00046, -0.616956, 0.465296, 2.1221, -1.76192, -0.333667, 5.90986, -0.25128, -0.46535, 2.1221, -1.76192, -0.46535, 1.86882, 1.75606, -0.424191, -1.35832, 1.81769, 0.88668, -1.35832, -0.616956, -0.424191, -1.35832, -0.616956, -0.46535, 1.86882, -0.6165) [node name="Person" type="CharacterBody3D"] script = ExtResource("1_dh77o") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] -transform = Transform3D(0.3, 0, 0, 0, 0.3, 0, 0, 0, 0.3, 0, 0, 0) +transform = Transform3D(-1.31134e-08, 0, 0.3, 0, 0.3, 0, -0.3, 0, -1.31134e-08, 0, 0, 0.368102) mesh = ExtResource("1_11yxf") +surface_material_override/1 = SubResource("ShaderMaterial_kmh38") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -transform = Transform3D(0.3, 0, 0, 0, 0.3, 0, 0, 0, 0.3, 0, 0, 0) -shape = SubResource("ConvexPolygonShape3D_dh77o") +transform = Transform3D(-1.31134e-08, 0, 0.3, 0, 0.3, 0, -0.3, 0, -1.31134e-08, 0, 0, 0.368102) +shape = SubResource("ConvexPolygonShape3D_dbviw") [node name="NavigationAgent3D" type="NavigationAgent3D" parent="."] avoidance_enabled = true debug_enabled = true + +[connection signal="navigation_finished" from="NavigationAgent3D" to="." method="_on_navigation_agent_3d_navigation_finished"] diff --git a/Scenes/Prefabs/cart.tscn b/Scenes/Prefabs/cart.tscn index 370e827..39f472d 100644 --- a/Scenes/Prefabs/cart.tscn +++ b/Scenes/Prefabs/cart.tscn @@ -39,7 +39,7 @@ cartTop = NodePath("Cart-top") mesh = ExtResource("1_ux2tx") [node name="NavigationRegion3D" type="NavigationRegion3D" parent="Cart-bottom"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.55366, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.138559, 0) navigation_mesh = SubResource("NavigationMesh_ru0md") [node name="NavigationObstacle3D" type="NavigationObstacle3D" parent="Cart-bottom/NavigationRegion3D"] diff --git a/Scenes/main.tscn b/Scenes/main.tscn index afdb330..ac572b8 100644 --- a/Scenes/main.tscn +++ b/Scenes/main.tscn @@ -114,4 +114,4 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 20.321, 0.384693, -59.426) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 180.354, 0.385, -59.426) [node name="Person" parent="." instance=ExtResource("5_kry3j")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.335692, 3.74189, -60.6947) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.335692, 3.32679, -60.6947) diff --git a/Scripts/person.gd b/Scripts/person.gd index 0453c57..edafac5 100644 --- a/Scripts/person.gd +++ b/Scripts/person.gd @@ -1,14 +1,27 @@ extends CharacterBody3D var nav_agent: NavigationAgent3D + +var shirt_shader: ShaderMaterial +var meshI: MeshInstance3D + +var start_pos: Vector3 + func _ready() -> void: nav_agent = $NavigationAgent3D + meshI = $MeshInstance3D + shirt_shader = meshI.get_surface_override_material(1) + Global.object_placed.connect(_on_object_placed) + set_random_shirt() + + start_pos = global_position #nav_agent.target_position = Vector3(-15.955,3.486,-58.942) func _physics_process(delta: float) -> void: var new_velocity = global_position.direction_to(nav_agent.get_next_path_position()) * 5.0 + look_at(nav_agent.target_position) velocity = new_velocity move_and_slide() @@ -16,3 +29,13 @@ func _physics_process(delta: float) -> void: func _on_object_placed(): nav_agent.target_position = Vector3(-14.305,3.486,-59.836) + + +func set_random_shirt(): + var new_shirt_color = Vector3(randf(),randf(),randf()) + shirt_shader.set_shader_parameter("shirt_color", new_shirt_color) + pass + + +func _on_navigation_agent_3d_navigation_finished() -> void: + nav_agent.target_position = start_pos diff --git a/Shaders/shirt.gdshader b/Shaders/shirt.gdshader new file mode 100644 index 0000000..da2330d --- /dev/null +++ b/Shaders/shirt.gdshader @@ -0,0 +1,16 @@ +shader_type spatial; +uniform vec3 shirt_color; + + +void vertex() { + // Called for every vertex the material is visible on. +} + +void fragment() { + ALBEDO = shirt_color; +} + +//void light() { +// // Called for every pixel for every light affecting the material. +// // Uncomment to replace the default light processing function with this one. +//} diff --git a/Shaders/shirt.gdshader.uid b/Shaders/shirt.gdshader.uid new file mode 100644 index 0000000..eb12b90 --- /dev/null +++ b/Shaders/shirt.gdshader.uid @@ -0,0 +1 @@ +uid://bm15rdsdxldwl