diff --git a/base/scenes/enemies/test_enemy.tscn b/base/scenes/enemies/test_enemy.tscn index 7508eee..d68e3ca 100644 --- a/base/scenes/enemies/test_enemy.tscn +++ b/base/scenes/enemies/test_enemy.tscn @@ -11,10 +11,6 @@ [ext_resource type="Texture2D" uid="uid://c57drlhnuicu5" path="res://base/assets/sprites/test_enemy/0007.png" id="9_83myg"] [ext_resource type="Script" uid="uid://biqn05eyrhdya" path="res://base/scripts/enemies/floor_mover.gd" id="10_rvsun"] -[sub_resource type="CylinderShape3D" id="CylinderShape3D_hmq60"] -height = 1.52902 -radius = 0.543945 - [sub_resource type="GDScript" id="GDScript_rvsun"] resource_name = "temp" script/source = "extends Node @@ -25,13 +21,17 @@ func _process(delta: float) -> void: $\"../../NavigationAgent3D\".target_position = get_tree().current_scene.get_node(\"%Player\").global_position " -[node name="TestEnemy" type="Node3D" groups=["enemy"]] +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_rvsun"] +height = 1.5095 + +[node name="TestEnemy" type="CharacterBody3D" groups=["enemy"]] +collision_layer = 4 [node name="RotationalSprite" type="Sprite3D" parent="."] transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0.97973, 0) billboard = 2 texture_filter = 0 -texture = ExtResource("1_7qny8") +texture = ExtResource("8_snoby") script = ExtResource("2_hmq60") rotations = Dictionary[float, Texture2D]({ 0.0: ExtResource("6_d1vpv"), @@ -45,23 +45,18 @@ rotations = Dictionary[float, Texture2D]({ 6.28319: ExtResource("6_d1vpv") }) -[node name="Hitbox" type="Area3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.181836, 0) -collision_layer = 4 -collision_mask = 0 - -[node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.584702, 0) -shape = SubResource("CylinderShape3D_hmq60") - [node name="NavigationAgent3D" type="NavigationAgent3D" parent="."] +debug_enabled = true [node name="Mover" type="Node" parent="." node_paths=PackedStringArray("navigation_agent", "move_target")] script = ExtResource("10_rvsun") navigation_agent = NodePath("../NavigationAgent3D") move_target = NodePath("..") max_speed = 2.0 -rotation_speed = 0.0872665 [node name="Node" type="Node" parent="Mover"] script = SubResource("GDScript_rvsun") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.766538, 0) +shape = SubResource("CapsuleShape3D_rvsun") diff --git a/base/scenes/rooms/navigation_test_scene.tscn b/base/scenes/rooms/navigation_test_scene.tscn index 6cba2c5..43a1d68 100644 --- a/base/scenes/rooms/navigation_test_scene.tscn +++ b/base/scenes/rooms/navigation_test_scene.tscn @@ -6,6 +6,7 @@ [sub_resource type="NavigationMesh" id="NavigationMesh_cmbee"] vertices = PackedVector3Array(-12.7732, 1, 8.2876, -3.27324, 1, 8.2876, -3.27324, 1, 6.2876, -1.02324, 1, 6.0376, -1.02324, 1, -4.4624, -12.7732, 1, -4.4624, 8.72676, 1.25, 7.0376, 7.22676, 1.75, 7.0376, 7.47676, 1.75, 8.0376, 11.7268, 1, 8.0376, 11.9768, 1, 9.2876, 12.7268, 1, 9.2876, 12.7268, 1, -4.4624, 8.72676, 1, 6.0376, 3.72676, 4.75, 16.5376, 3.47676, 4.75, 13.0376, 2.72676, 4.75, 13.0376, 2.47676, 4.75, 16.5376, -0.273237, 4.5, 8.0376, -2.27324, 4.75, 7.0376, -1.27324, 4.75, 10.0376, -0.273237, 4.75, 9.0376, 8.22676, 4.75, 17.0376, 8.22676, 4.75, 16.5376, -2.27324, 4.75, 17.0376, 10.2268, 4.75, 10.0376, 10.9768, 4.75, 9.0376, -1.27324, 4.75, 16.5376, 10.4768, 4.75, 17.7876, 10.9768, 4.75, 17.7876, -0.916094, 4.75, 7.0376, -12.7732, 1, 15.7876, -3.27324, 1, 15.7876, 9.47676, 1, 16.7876, 9.22676, 1, 16.7876, 8.97676, 1, 18.0376, 9.72676, 1, 18.7876, 12.7268, 1, 29.0376, 11.9768, 1, 18.5376, -1.02324, 1, 18.0376, -1.02324, 1, 29.0376, 8.97676, 1, 15.5376, 9.47676, 1, 11.0376, -0.523237, 1, 15.5376, 1.72676, 1, 15.5376, 1.97676, 1, 12.0376, -0.523237, 1, 11.0376, 4.22676, 1, 12.0376, 4.47676, 1, 15.5376, -3.27324, 1, 17.7876, -12.7732, 1, 29.0376) polygons = [PackedInt32Array(2, 1, 0), PackedInt32Array(4, 3, 2), PackedInt32Array(0, 5, 2), PackedInt32Array(2, 5, 4), PackedInt32Array(7, 6, 8), PackedInt32Array(8, 6, 9), PackedInt32Array(10, 9, 11), PackedInt32Array(11, 9, 12), PackedInt32Array(3, 4, 13), PackedInt32Array(13, 4, 12), PackedInt32Array(6, 13, 9), PackedInt32Array(9, 13, 12), PackedInt32Array(15, 14, 16), PackedInt32Array(16, 14, 17), PackedInt32Array(21, 20, 18), PackedInt32Array(18, 20, 19), PackedInt32Array(14, 23, 22), PackedInt32Array(14, 22, 17), PackedInt32Array(17, 22, 24), PackedInt32Array(26, 25, 21), PackedInt32Array(21, 25, 20), PackedInt32Array(27, 17, 24), PackedInt32Array(27, 24, 20), PackedInt32Array(20, 24, 19), PackedInt32Array(28, 25, 29), PackedInt32Array(29, 25, 26), PackedInt32Array(19, 30, 18), PackedInt32Array(18, 30, 7), PackedInt32Array(18, 7, 8), PackedInt32Array(0, 1, 31), PackedInt32Array(31, 1, 32), PackedInt32Array(34, 33, 35), PackedInt32Array(35, 33, 36), PackedInt32Array(36, 38, 37), PackedInt32Array(10, 11, 38), PackedInt32Array(38, 11, 37), PackedInt32Array(35, 36, 39), PackedInt32Array(39, 36, 40), PackedInt32Array(40, 36, 37), PackedInt32Array(34, 41, 33), PackedInt32Array(33, 41, 42), PackedInt32Array(44, 43, 45), PackedInt32Array(45, 43, 46), PackedInt32Array(48, 47, 41), PackedInt32Array(41, 47, 42), PackedInt32Array(45, 46, 47), PackedInt32Array(47, 46, 42), PackedInt32Array(31, 32, 49), PackedInt32Array(49, 39, 40), PackedInt32Array(31, 49, 50), PackedInt32Array(50, 49, 40)] +agent_height = 1.51 [sub_resource type="ORMMaterial3D" id="ORMMaterial3D_yvrvx"] albedo_color = Color(1, 0, 0, 1) diff --git a/base/scripts/enemies/floor_mover.gd b/base/scripts/enemies/floor_mover.gd index a0fd22f..ce0da2e 100644 --- a/base/scripts/enemies/floor_mover.gd +++ b/base/scripts/enemies/floor_mover.gd @@ -3,16 +3,20 @@ extends Node class_name FloorMover @export var navigation_agent : NavigationAgent3D -@export var move_target : Node3D +@export var move_target : CharacterBody3D @export_category("Velocity Settings") @export var max_speed : float -@export_range(0,720,0.1,"or_greater","radians_as_degrees","exp") var rotation_speed : float + +@onready var gravity : float = ProjectSettings.get_setting("physics/3d/default_gravity") +@onready var gravity_vector : Vector3 = ProjectSettings.get_setting("physics/3d/default_gravity_vector") func _physics_process(delta: float) -> void: - if navigation_agent.is_navigation_finished(): return - - if navigation_agent.is_target_reachable(): + if navigation_agent.is_target_reachable() and move_target.is_on_floor(): var pos = navigation_agent.get_next_path_position() move_target.look_at(pos) - move_target.global_position += move_target.global_position.direction_to(pos) * max_speed * delta + move_target.velocity = move_target.global_position.direction_to(pos) * max_speed + + if(move_target.is_on_floor() == false): + move_target.velocity -= gravity_vector * gravity_vector + move_target.move_and_slide()