extends RigidBody3D signal died @onready var bat_model: Node3D = %bat_model @onready var player: CharacterBody3D = get_node("/root/Game/Player") @onready var corpse_timer: Timer = $CorpseTimer @onready var hurt_box: Area3D = %HurtBox var speed = randf_range(2.0, 4.0) var health = 100.0 func take_damage(damage: float = 25.0) -> void: if is_zero_approx(health): return # catch shooting mob on ground and stopping it from despawning else: %HurtSound.play() bat_model.hurt() health = clampf((health - damage), 0.0, health) if is_zero_approx(health): # TODO: do more with this set_physics_process(false) gravity_scale = 1.0 %DieSound.play() var die_direction = global_position.direction_to(player.global_position) * -1.0 var blerg_force = Vector3.UP * randf_range(2.0, 5.0) apply_central_impulse(die_direction * 8.0 + blerg_force) died.emit() corpse_timer.start() func _on_corpse_timer_timeout() -> void: queue_free() func _physics_process(delta: float) -> void: var direction: Vector3 = global_position.direction_to(player.global_position) direction.y = 0.0 linear_velocity = direction * speed bat_model.rotation.y = Vector3.MODEL_FRONT.signed_angle_to(direction, Vector3.UP) var targets = hurt_box.get_overlapping_bodies() if not targets.is_empty(): for t in targets: if t.has_method("hurt"): t.hurt(5*delta)