first commit
This commit is contained in:
127
Scripts/CameraMove.gd
Normal file
127
Scripts/CameraMove.gd
Normal file
@@ -0,0 +1,127 @@
|
||||
extends Node3D
|
||||
|
||||
@export_group("Riferimenti Camere")
|
||||
@export var camera_iso : Camera3D
|
||||
@export var camera_frontale : Camera3D
|
||||
@export var camera_laterale : Camera3D
|
||||
@export var camera_laterale_2 : Camera3D # Nuova Camera 4
|
||||
@export var camera_alta : Camera3D # Nuova Camera 5
|
||||
|
||||
@export_group("Movimento Camera 1")
|
||||
@export var move_speed : float = 20.0
|
||||
@export var rotation_speed : float = 0.2
|
||||
|
||||
@export_group("Cinematic Mode")
|
||||
@export var tempo_cambio_camera : float = 10.0 # Quanti secondi dura ogni inquadratura
|
||||
|
||||
var is_moving_enabled : bool = true
|
||||
|
||||
# --- Variabili Cinematic Mode ---
|
||||
var is_cinematic_mode : bool = false
|
||||
var cinematic_timer : float = 0.0
|
||||
var cinematic_index : int = 0
|
||||
var array_camere : Array[Camera3D] = []
|
||||
|
||||
func _ready():
|
||||
# Creiamo un array con le telecamere valide per ciclarle facilmente
|
||||
if camera_iso: array_camere.append(camera_iso)
|
||||
if camera_frontale: array_camere.append(camera_frontale)
|
||||
if camera_laterale: array_camere.append(camera_laterale)
|
||||
if camera_laterale_2: array_camere.append(camera_laterale_2)
|
||||
if camera_alta: array_camere.append(camera_alta)
|
||||
|
||||
# All'inizio, assicuriamoci che la CameraIso sia quella attiva
|
||||
if camera_iso:
|
||||
camera_iso.make_current()
|
||||
|
||||
func _input(event):
|
||||
# Cambio Camera Manuale e Cinematic Toggle
|
||||
if event is InputEventKey and event.pressed and not event.echo:
|
||||
|
||||
# --- TASTO C: TOGGLE CINEMATIC MODE ---
|
||||
if event.keycode == KEY_C:
|
||||
is_cinematic_mode = !is_cinematic_mode
|
||||
if is_cinematic_mode:
|
||||
cinematic_timer = 0.0 # Azzera il timer
|
||||
# Cerca qual è la camera attualmente attiva per iniziare il ciclo da lì
|
||||
for i in range(array_camere.size()):
|
||||
if array_camere[i].current:
|
||||
cinematic_index = i
|
||||
break
|
||||
print("Cinematic Mode: ATTIVATA")
|
||||
else:
|
||||
print("Cinematic Mode: DISATTIVATA")
|
||||
return # Usciamo per non eseguire altri controlli in questo frame
|
||||
|
||||
# --- CONTROLLI MANUALI (1-5) ---
|
||||
var intervento_manuale = false
|
||||
|
||||
if event.keycode == KEY_1 and camera_iso:
|
||||
camera_iso.make_current()
|
||||
is_moving_enabled = true
|
||||
intervento_manuale = true
|
||||
|
||||
elif event.keycode == KEY_2 and camera_frontale:
|
||||
camera_frontale.make_current()
|
||||
is_moving_enabled = false
|
||||
intervento_manuale = true
|
||||
|
||||
elif event.keycode == KEY_3 and camera_laterale:
|
||||
camera_laterale.make_current()
|
||||
is_moving_enabled = false
|
||||
intervento_manuale = true
|
||||
|
||||
elif event.keycode == KEY_4 and camera_laterale_2:
|
||||
camera_laterale_2.make_current()
|
||||
is_moving_enabled = false
|
||||
intervento_manuale = true
|
||||
|
||||
elif event.keycode == KEY_5 and camera_alta:
|
||||
camera_alta.make_current()
|
||||
is_moving_enabled = false
|
||||
intervento_manuale = true
|
||||
|
||||
# Se l'utente preme un numero per cambiare camera manualmente, spegni la cinematic mode
|
||||
if intervento_manuale and is_cinematic_mode:
|
||||
is_cinematic_mode = false
|
||||
print("Cinematic Mode: DISATTIVATA (Intervento manuale)")
|
||||
|
||||
# Rotazione: Solo se il movimento è abilitato (Camera 1)
|
||||
if is_moving_enabled:
|
||||
if event is InputEventMouseMotion and Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||
rotate_y(deg_to_rad(-event.relative.x * rotation_speed))
|
||||
|
||||
func _process(delta):
|
||||
# --- LOGICA CINEMATIC MODE ---
|
||||
if is_cinematic_mode and array_camere.size() > 0:
|
||||
cinematic_timer += delta
|
||||
if cinematic_timer >= tempo_cambio_camera:
|
||||
cinematic_timer = 0.0
|
||||
# Passa alla camera successiva e se è l'ultima ricomincia da zero
|
||||
cinematic_index = (cinematic_index + 1) % array_camere.size()
|
||||
|
||||
var next_cam = array_camere[cinematic_index]
|
||||
next_cam.make_current()
|
||||
|
||||
# Abilita il movimento WASD solo se la camera inquadrata è quella isometrica (la 1)
|
||||
is_moving_enabled = (next_cam == camera_iso)
|
||||
|
||||
# --- LOGICA DI MOVIMENTO WASD ---
|
||||
# Se siamo in camera 2, 3, 4 o 5, non processare il movimento WASD
|
||||
if not is_moving_enabled:
|
||||
return
|
||||
|
||||
var input_dir = Vector3.ZERO
|
||||
if Input.is_key_pressed(KEY_W): input_dir.z -= 1
|
||||
if Input.is_key_pressed(KEY_S): input_dir.z += 1
|
||||
if Input.is_key_pressed(KEY_A): input_dir.x -= 1
|
||||
if Input.is_key_pressed(KEY_D): input_dir.x += 1
|
||||
|
||||
if input_dir != Vector3.ZERO:
|
||||
input_dir = input_dir.normalized()
|
||||
var forward = transform.basis.z
|
||||
var right = transform.basis.x
|
||||
forward.y = 0
|
||||
right.y = 0
|
||||
var motion = (forward * input_dir.z + right * input_dir.x).normalized()
|
||||
position += motion * move_speed * delta
|
||||
Reference in New Issue
Block a user