From 3ef1fc4df2e3178d37061ad13b5d366771193dd2 Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Sun, 22 Sep 2024 20:46:38 +0100 Subject: Add enemy spawning and ability to kill enemies --- scripts/enemy.gd | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'scripts/enemy.gd') diff --git a/scripts/enemy.gd b/scripts/enemy.gd index 716493c..7060ab2 100644 --- a/scripts/enemy.gd +++ b/scripts/enemy.gd @@ -18,7 +18,8 @@ var astar: AStar3D var tar_vec: Vector3 var gravity : float = ProjectSettings.get_setting("physics/3d/default_gravity") -var original_color: Color +var original_material: StandardMaterial3D +@onready var red_material = preload("res://models/red_material.tres") var mesh_ready = false @@ -27,6 +28,7 @@ func _ready() -> void: motion_mode = MotionMode.MOTION_MODE_GROUNDED NavigationServer3D.connect("map_changed", map_changed) + original_material = $MeshInstance3D.get_active_material(0) func map_changed(_rid): print("Map changed") @@ -117,9 +119,7 @@ func _physics_process(delta: float) -> void: func on_hit(_hit_position: Vector3) -> void: if $HitTimer.is_stopped(): - var material: StandardMaterial3D = $MeshInstance3D.get_active_material(0) - original_color = material.albedo_color - material.albedo_color = Color(1.0, 0.0, 0.0, 1.0) + $MeshInstance3D.set_surface_override_material(0, red_material) $HitTimer.start() func _on_level_generator_astar_created(in_astar: AStar3D) -> void: @@ -127,6 +127,8 @@ func _on_level_generator_astar_created(in_astar: AStar3D) -> void: has_astar = true func _on_hit_timer_timeout() -> void: - var material: StandardMaterial3D = $MeshInstance3D.get_active_material(0) - material.albedo_color = original_color + $MeshInstance3D.set_surface_override_material(0, original_material) $HitTimer.stop() + + get_parent().remove_child(self) + queue_free() -- cgit