44 lines
997 B
GDScript
44 lines
997 B
GDScript
class_name PoliceCar
|
|
extends CharacterBody3D
|
|
|
|
const FRAME_IDXS := 10
|
|
|
|
@export var dot_curve: Curve
|
|
|
|
var health := 10.
|
|
var frame_idx := 0
|
|
|
|
func _ready() -> void:
|
|
frame_idx = randi() % FRAME_IDXS
|
|
|
|
func _update_nav_agent() -> void:
|
|
%NavAgent.target_position = Player.instance.global_position
|
|
|
|
var frame_count := 0
|
|
func _process(delta: float) -> void:
|
|
frame_count = (frame_count + 1) % FRAME_IDXS
|
|
if frame_count == frame_idx:
|
|
_update_nav_agent()
|
|
|
|
var dir := global_position.direction_to(%NavAgent.get_next_path_position())
|
|
dir.y = 0
|
|
var dot_power := dot_curve.sample(dir.dot(velocity.normalized()))
|
|
velocity += dir * 8. * delta * dot_power
|
|
velocity = velocity.limit_length(8.)
|
|
move_and_slide()
|
|
|
|
rotation.y = Vector2(velocity.x, -velocity.z).angle()
|
|
position.y = 0.01
|
|
|
|
func hit(_proj: PlayerProjectile, damage: float) -> bool:
|
|
health -= damage
|
|
if health <= 0:
|
|
queue_free()
|
|
|
|
return true
|
|
|
|
|
|
func _on_hurtbox_body_entered(body: Node3D) -> void:
|
|
if body is Player:
|
|
body.damage(self)
|
|
|