Mostrando entradas con la etiqueta GDSCRIPT SOLO DISPARA DE 1 EN 1 ALEMPEZAR A PRESIONAR TECLA; ;GODOT 4.5;;. Mostrar todas las entradas
Mostrando entradas con la etiqueta GDSCRIPT SOLO DISPARA DE 1 EN 1 ALEMPEZAR A PRESIONAR TECLA; ;GODOT 4.5;;. Mostrar todas las entradas

domingo, 16 de noviembre de 2025

GDSCRIPT SOLO DISPARA DE 1 EN 1 AL EMPEZAR A PRESIONAR TECLA; GODOT 4.5;

 extends Area3D


var Bullet = preload("res://PROTAGONISTA/area_3dPROLLECTIL RIFLE.tscn")


# --- Variables de control para el cooldown ---

var right_mouse_fire_cooldown: float = 0.4

var can_fire_right_mouse: bool = true


# --- Nodos Timer ---

var right_mouse_timer: Timer


# --- Referencia al nodo del modelo 3D (para la rotación) ---

var player_mesh: MeshInstance3D



func _ready() -> void:

# --- Inicialización del temporizador para el Botón Derecho ---

right_mouse_timer = Timer.new()

add_child(right_mouse_timer)

right_mouse_timer.wait_time = right_mouse_fire_cooldown

right_mouse_timer.one_shot = true

# Al terminar el tiempo, volvemos a permitir el disparo

right_mouse_timer.timeout.connect(func(): can_fire_right_mouse = true)


# --- OBTENER REFERENCIA al nodo MeshInstance3D ---

player_mesh = get_node("MeshInstance3D")



func _input(event: InputEvent) -> void:

if event is InputEventMouseButton:

# 🎯 CAMBIO CLAVE: Disparo al EMPEZAR a presionar 🔫

# Verificamos si es el botón derecho Y SI ESTÁ presionado (event.is_pressed())

if event.button_index == MOUSE_BUTTON_RIGHT and event.is_pressed(): 

if can_fire_right_mouse:

can_fire_right_mouse = false

instantiate_bullet()

right_mouse_timer.start()


# NOTA: La liberación del botón ahora no hace nada porque no hay código que la compruebe.



func _process(delta: float) -> void:

# --- LÓGICA de rotación (Se mantiene aquí) ---

if player_mesh:

if Input.is_key_pressed(KEY_Z):

player_mesh.rotate_object_local(Vector3.FORWARD, 1.0 * delta)

if Input.is_key_pressed(KEY_X):

player_mesh.rotate_object_local(Vector3.FORWARD, -1.0 * delta)



# --- Función unificada para instanciar la bala ---

func instantiate_bullet() -> void:

var bullet = Bullet.instantiate()

add_child(bullet)