2023-11-25 17:31:47 +00:00
|
|
|
extends StaticBody3D
|
|
|
|
|
|
|
|
@onready var player: Player = get_tree().root.find_children("Player", "Player", true, false)[0]
|
|
|
|
|
|
|
|
|
|
|
|
@export var max_distance: float = 30.0
|
|
|
|
@export var rotation_speed = 0.1
|
2023-11-25 17:49:48 +00:00
|
|
|
@export var initial_cooldown: float = 0.1
|
2023-11-25 17:31:47 +00:00
|
|
|
|
|
|
|
var bullet = preload("res://obstacles/bullet.tscn")
|
|
|
|
var cooldown = 0
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
var distance = player.global_position.distance_to(global_position)
|
|
|
|
if distance > max_distance:
|
|
|
|
return
|
|
|
|
|
|
|
|
rotation.y = (global_position - player.global_position).signed_angle_to(Vector3.FORWARD, Vector3.DOWN) + PI/2
|
|
|
|
|
|
|
|
if cooldown > 0:
|
|
|
|
cooldown -= delta
|
|
|
|
else:
|
|
|
|
var bull = bullet.instantiate()
|
|
|
|
bull.global_position = global_position
|
2023-11-25 17:49:48 +00:00
|
|
|
|
|
|
|
var diff_x = player.global_position.x - global_position.x
|
|
|
|
var diff_z = player.global_position.z - global_position.z
|
|
|
|
|
|
|
|
var diff = Vector3(diff_x, 0, diff_z)
|
|
|
|
var norm = diff.normalized()
|
|
|
|
|
|
|
|
bull.set_linear_velocity(norm * 50)
|
2023-11-25 17:31:47 +00:00
|
|
|
|
|
|
|
get_tree().root.add_child(bull)
|
2023-11-25 17:49:48 +00:00
|
|
|
cooldown = initial_cooldown
|
2023-11-25 17:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|