enemy now can walk on slopes

This commit is contained in:
Rendo 2025-07-27 21:11:10 +05:00
commit eec69524ee
4 changed files with 35 additions and 20 deletions

View file

@ -31,7 +31,7 @@ func _process(delta: float) -> void:
transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0.97973, 0)
billboard = 2
texture_filter = 0
texture = ExtResource("3_rvsun")
texture = ExtResource("1_7qny8")
script = ExtResource("2_hmq60")
rotations = Dictionary[float, Texture2D]({
0.0: ExtResource("6_d1vpv"),
@ -60,7 +60,7 @@ shape = SubResource("CylinderShape3D_hmq60")
script = ExtResource("10_rvsun")
navigation_agent = NodePath("../NavigationAgent3D")
move_target = NodePath("..")
max_speed = 10.0
max_speed = 2.0
rotation_speed = 0.0872665
[node name="Node" type="Node" parent="Mover"]

View file

@ -4,8 +4,8 @@
[ext_resource type="PackedScene" uid="uid://dwx5tcatj35gu" path="res://base/scenes/player.tscn" id="2_2xi8s"]
[sub_resource type="NavigationMesh" id="NavigationMesh_cmbee"]
vertices = PackedVector3Array(-12.7732, 1, 10.2876, -2.77324, 1, 10.2876, -2.77324, 1, 8.2876, -0.523237, 1, 8.0376, -0.523237, 1, -4.4624, -12.7732, 1, -4.4624, 11.2268, 1, 8.0376, 11.4768, 1, 10.0376, 12.7268, 1, 9.7876, 12.7268, 1, -4.4624, -1.77324, 4.75, 9.0376, -1.77324, 4.75, 17.0376, -1.27324, 4.75, 17.0376, -1.27324, 4.75, 9.0376, 9.47676, 1, 17.0376, 9.22676, 1, 17.0376, 8.97676, 1, 18.0376, 9.72676, 1, 18.7876, 12.7268, 1, 29.0376, 11.4768, 1, 18.5376, -0.523237, 1, 18.0376, -0.523237, 1, 29.0376, 8.97676, 1, 16.0376, 9.47676, 1, 10.0376, -0.523237, 1, 16.0376, 2.22676, 1, 16.0376, 2.22676, 1, 12.2876, -0.523237, 1, 10.0376, 4.22676, 1, 12.0376, 4.47676, 1, 16.0376, -12.7732, 1, 15.7876, -2.77324, 1, 15.7876, 2.97676, 4.75, 16.7876, 3.72676, 4.75, 17.0376, 3.47676, 4.75, 13.0376, -2.77324, 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(3, 4, 6), PackedInt32Array(6, 4, 9), PackedInt32Array(13, 12, 10), PackedInt32Array(10, 12, 11), PackedInt32Array(15, 14, 16), PackedInt32Array(16, 14, 17), PackedInt32Array(17, 19, 18), PackedInt32Array(7, 8, 19), PackedInt32Array(19, 8, 18), PackedInt32Array(16, 17, 20), PackedInt32Array(20, 17, 21), PackedInt32Array(21, 17, 18), PackedInt32Array(15, 22, 14), PackedInt32Array(14, 22, 23), PackedInt32Array(25, 24, 26), PackedInt32Array(26, 24, 27), PackedInt32Array(29, 28, 22), PackedInt32Array(22, 28, 23), PackedInt32Array(26, 27, 28), PackedInt32Array(28, 27, 23), PackedInt32Array(0, 1, 30), PackedInt32Array(30, 1, 31), PackedInt32Array(32, 34, 33), PackedInt32Array(30, 31, 35), PackedInt32Array(35, 20, 21), PackedInt32Array(30, 35, 36), PackedInt32Array(36, 35, 21)]
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)]
[sub_resource type="ORMMaterial3D" id="ORMMaterial3D_yvrvx"]
albedo_color = Color(1, 0, 0, 1)
@ -35,33 +35,50 @@ size = Vector3(15.1416, 1, 16.73)
material = SubResource("ORMMaterial3D_yvrvx")
[node name="CSGBox3D5" type="CSGBox3D" parent="NavigationRegion3D/CSGCombiner3D"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 4.35131, 1.95319, 9.02124)
size = Vector3(0.87915, 4.90637, 12.7579)
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 4.35131, 1.95319, 9.49359)
size = Vector3(1.82385, 4.90637, 12.7579)
material = SubResource("ORMMaterial3D_yvrvx")
[node name="CSGBox3D6" type="CSGBox3D" parent="NavigationRegion3D/CSGCombiner3D"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -1.61005, 1.95319, 13.0554)
size = Vector3(0.87915, 4.90637, 8.94635)
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -1.96863, 1.95319, 12.0486)
size = Vector3(1.59631, 4.90637, 10.96)
material = SubResource("ORMMaterial3D_yvrvx")
[node name="CSGBox3D8" type="CSGBox3D" parent="NavigationRegion3D/CSGCombiner3D"]
transform = Transform3D(1.31134e-07, 0, -1, 0, 1, 0, 1, 0, 1.31134e-07, 3.21596, 1.95319, 17.0787)
size = Vector3(0.87915, 4.90637, 10.5567)
transform = Transform3D(1.31134e-07, 0, -1, 0, 1, 0, 1, 0, 1.31134e-07, 3.21596, 1.95319, 16.7973)
size = Vector3(1.44202, 4.90637, 10.5567)
material = SubResource("ORMMaterial3D_yvrvx")
[node name="CSGBox3D9" type="CSGBox3D" parent="NavigationRegion3D/CSGCombiner3D"]
transform = Transform3D(1, 0, 1.74846e-07, 0, 1, 0, -1.74846e-07, 0, 1, 3.4037, 1.95319, 15.0201)
size = Vector3(0.87915, 4.90637, 4.93153)
transform = Transform3D(1, 0, 1.74846e-07, 0, 1, 0, -1.74846e-07, 0, 1, 3.07833, 1.95319, 15.0201)
size = Vector3(1.52991, 4.90637, 4.93153)
material = SubResource("ORMMaterial3D_yvrvx")
[node name="CSGBox3D7" type="CSGBox3D" parent="NavigationRegion3D/CSGCombiner3D"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 10.495, 1.95319, 13.3886)
size = Vector3(0.87915, 4.90637, 9.60895)
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 10.7086, 1.95319, 13.3886)
size = Vector3(1.30627, 4.90637, 9.60895)
material = SubResource("ORMMaterial3D_yvrvx")
[node name="CSGPolygon3D" type="CSGPolygon3D" parent="NavigationRegion3D/CSGCombiner3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.50082, 8.56971)
polygon = PackedVector2Array(-1.16205, -0.0740491, -1.18576, 3.89251, 9.72225, 0.0251404)
depth = 2.0
[node name="TestEnemy" parent="." instance=ExtResource("1_cmbee")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.16028, 0.549035, 11.0707)
[node name="TestEnemy2" parent="." instance=ExtResource("1_cmbee")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.34192, 0.549035, 18.1813)
[node name="TestEnemy3" parent="." instance=ExtResource("1_cmbee")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.0985, 0.549035, 10.2576)
[node name="TestEnemy4" parent="." instance=ExtResource("1_cmbee")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.00199, 0.549035, 4.24815)
[node name="TestEnemy5" parent="." instance=ExtResource("1_cmbee")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.6038, 0.549035, 2.9313)
[node name="Player" parent="." instance=ExtResource("2_2xi8s")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7.24002, 1.52635, 15.011)

View file

@ -9,7 +9,7 @@ func _process(delta: float) -> void:
if Engine.is_editor_hint():
camera = EditorInterface.get_editor_viewport_3d().get_camera_3d()
# Angle between camera's -basis.z (forward direction) and direction to camera
var angle = vec3_to_vec2(-global_transform.basis.z).angle_to(vec3_to_vec2(global_position - camera.global_position)) + PI
var angle = vec3_to_vec2(global_transform.basis.z).angle_to(vec3_to_vec2(global_position - camera.global_position)) + PI
var chosen_index = 0
for i in rotations.keys():
if abs(angle-i) < abs(angle-chosen_index):

View file

@ -13,8 +13,6 @@ func _physics_process(delta: float) -> void:
if navigation_agent.is_navigation_finished(): return
if navigation_agent.is_target_reachable():
var direction_to_next = (navigation_agent.get_next_path_position() - move_target.global_position).normalized()
var delta_angle = clamp(move_target.basis.z.signed_angle_to(direction_to_next,Vector3.UP),-rotation_speed,rotation_speed)
move_target.rotation.y += delta_angle
move_target.global_position += move_target.basis.z * max_speed * delta
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