1
Fork 0
mirror of https://github.com/Steffo99/cinnos.git synced 2024-11-21 23:54:20 +00:00
cinnos/Torretta.gd

47 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

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 18:25:25 +00:00
@export var initial_cooldown: float = 0.2
2023-11-25 17:31:47 +00:00
2023-11-25 19:37:07 +00:00
@export var bullet = preload("res://obstacles/bullet.tscn")
2023-11-25 17:31:47 +00:00
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()
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()
2023-11-25 18:25:25 +00:00
bull.position = global_position
2023-11-25 17:49:48 +00:00
bull.set_linear_velocity(norm * 50)
2023-11-25 18:25:25 +00:00
bull.rotation.y = diff.signed_angle_to(Vector3.FORWARD, Vector3.DOWN)
get_tree().root.find_child("Root", true, false).add_child(bull)
2023-11-25 17:31:47 +00:00
2023-11-25 17:49:48 +00:00
cooldown = initial_cooldown
2023-11-25 17:31:47 +00:00