bcp de characters
This commit is contained in:
@@ -2,11 +2,90 @@ extends SpringArm3D
|
||||
|
||||
@onready var player: CharacterBody3D = $"../.."
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if player.third_person and event is InputEventMouseMotion :
|
||||
player.rotation.y -= event.relative.x * 0.005
|
||||
player.rotation.y = wrapf( player.rotation.y, 0.0, TAU )
|
||||
# --- Paramètres de mouvement ---
|
||||
@export var max_follow_speed: float = 3.0
|
||||
@export var speed_acceleration: float = 2.0
|
||||
@export var height_offset: float = 2.5
|
||||
@export var wait_time: float = 0.5
|
||||
|
||||
# --- Paramètres de Dialogue ---
|
||||
@export var dialog_zoom_length: float = 2.0
|
||||
@export var dialog_side_offset: float = 1.0
|
||||
@export var transition_speed: float = 4.0 # Gère la vitesse du zoom, du décalage ET de la rotation en dialog
|
||||
|
||||
@onready var normal_spring_length: float = spring_length
|
||||
|
||||
var delay_timer: float = 0.0
|
||||
var current_follow_speed: float = 0.0
|
||||
var current_side_offset: float = 0.0
|
||||
var target_side_offset: float = 0.0
|
||||
var is_in_dialog: bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
top_level = true
|
||||
|
||||
func set_dialog_mode(npc_position: Vector3 = Vector3.ZERO, force_pos=-1) -> void:
|
||||
is_in_dialog = !is_in_dialog
|
||||
|
||||
if is_in_dialog:
|
||||
var direction_to_npc = (npc_position - player.global_position).normalized()
|
||||
var right_dot = global_transform.basis.x.dot(direction_to_npc)
|
||||
|
||||
rotation.x -= event.relative.y * 0.005
|
||||
rotation.x = clamp( rotation.x, -PI/2, PI/4 )
|
||||
if right_dot >= 0 :
|
||||
target_side_offset = dialog_side_offset
|
||||
else:
|
||||
target_side_offset = -dialog_side_offset
|
||||
|
||||
if force_pos == 0 :
|
||||
target_side_offset = dialog_side_offset
|
||||
elif force_pos == 1 :
|
||||
target_side_offset = -dialog_side_offset
|
||||
else:
|
||||
target_side_offset = 0.0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_instance_valid(player):
|
||||
return
|
||||
|
||||
var target_rotation_y = player.global_rotation.y
|
||||
|
||||
# ==========================================
|
||||
# 1. GESTION DE LA ROTATION (Avant la position !)
|
||||
# ==========================================
|
||||
if is_in_dialog:
|
||||
delay_timer = 0.3
|
||||
current_follow_speed = 0.5
|
||||
|
||||
# La caméra tourne doucement pour se mettre dans le dos du joueur.
|
||||
# On utilise transition_speed pour que ça se finisse en même temps que le zoom.
|
||||
global_rotation.y = lerp_angle(global_rotation.y, target_rotation_y, transition_speed * delta)
|
||||
|
||||
else:
|
||||
if player.can_play:
|
||||
# Comportement normal d'exploration (Le vieux Zelda)
|
||||
var angle_diff = abs(angle_difference(global_rotation.y, target_rotation_y))
|
||||
|
||||
if angle_diff > 0.02 and player.velocity.length() > 0.1:
|
||||
delay_timer += delta
|
||||
else:
|
||||
delay_timer = 0.3
|
||||
current_follow_speed = 0.5
|
||||
|
||||
if delay_timer >= wait_time:
|
||||
current_follow_speed = move_toward(current_follow_speed, max_follow_speed, speed_acceleration * delta)
|
||||
global_rotation.y = lerp_angle(global_rotation.y, target_rotation_y, current_follow_speed * delta)
|
||||
|
||||
|
||||
# ==========================================
|
||||
# 2. GESTION DU ZOOM ET DU DECALAGE
|
||||
# ==========================================
|
||||
var target_length = dialog_zoom_length if is_in_dialog else normal_spring_length
|
||||
|
||||
spring_length = lerp(spring_length, target_length, transition_speed * delta)
|
||||
current_side_offset = lerp(current_side_offset, target_side_offset, transition_speed * delta)
|
||||
|
||||
# On récupère le vecteur "Droite" MAINTENANT, car la rotation vient juste d'être mise à jour au-dessus.
|
||||
var right_direction = global_transform.basis.x
|
||||
|
||||
# On applique la position finale (Joueur + Hauteur + Décalage latéral)
|
||||
global_position = player.global_position + Vector3(0, height_offset, 0) + (right_direction * current_side_offset)
|
||||
|
||||
Reference in New Issue
Block a user