feat: the rebuild gamemode of "Gauntlet"
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
extends Node
|
||||
|
||||
# ScreenShakeManager - Handles camera shake effects for impact feedback
|
||||
# ScreenShakeManager - Camera-local shake that follows the player
|
||||
|
||||
var camera: Camera3D
|
||||
var shake_intensity: float = 0.0
|
||||
var shake_duration: float = 0.0
|
||||
var shake_timer: float = 0.0
|
||||
var target_position: Vector3 # Replaces original_position
|
||||
var shake_offset: Vector3 = Vector3.ZERO
|
||||
|
||||
# Shake presets
|
||||
const SHAKE_TARGETED: Dictionary = {"intensity": 0.15, "duration": 0.4}
|
||||
@@ -14,19 +14,33 @@ const SHAKE_GOAL_COMPLETE: Dictionary = {"intensity": 0.1, "duration": 0.3}
|
||||
const SHAKE_LIGHT: Dictionary = {"intensity": 0.05, "duration": 0.2}
|
||||
|
||||
func initialize(p_camera: Camera3D):
|
||||
"""Initialize with specific camera instance."""
|
||||
camera = p_camera
|
||||
if camera:
|
||||
target_position = camera.position
|
||||
print("[ScreenShakeManager] Initialized with camera: ", camera.name)
|
||||
else:
|
||||
push_warning("[ScreenShakeManager] Initialized with null camera")
|
||||
|
||||
func set_target_position(new_pos: Vector3, duration: float = 1.0):
|
||||
"""Smoothly transition to a new base camera position."""
|
||||
if target_position == new_pos:
|
||||
func shake(intensity: float, duration: float) -> void:
|
||||
"""Trigger a camera shake. Intensity in world units, duration in seconds."""
|
||||
if intensity <= 0 or duration <= 0:
|
||||
return
|
||||
|
||||
# Tween the target position
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "target_position", new_pos, duration).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
# Take the stronger shake if already active
|
||||
if shake_timer > 0 and intensity <= shake_intensity:
|
||||
return
|
||||
shake_intensity = intensity
|
||||
shake_duration = duration
|
||||
shake_timer = duration
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not camera or not is_instance_valid(camera):
|
||||
return
|
||||
if shake_timer > 0:
|
||||
shake_timer -= delta
|
||||
var progress = shake_timer / shake_duration
|
||||
# Fade out intensity as timer expires
|
||||
var current_intensity = shake_intensity * progress
|
||||
# Random offset within intensity range
|
||||
shake_offset = Vector3(
|
||||
randf_range(-current_intensity, current_intensity),
|
||||
randf_range(-current_intensity, current_intensity) * 0.5,
|
||||
randf_range(-current_intensity, current_intensity)
|
||||
)
|
||||
camera.position += shake_offset
|
||||
else:
|
||||
shake_offset = Vector3.ZERO
|
||||
|
||||
Reference in New Issue
Block a user