Advertisement
Zunesha

Screen Shake na Godot 4 simples

Sep 13th, 2024
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.69 KB | Gaming | 0 0
  1. Screen Shake na Godot 4 simples :
  2.  
  3. extends Camera2D
  4.  
  5. @export var shake_intensity: float = 5.0  # Intensidade do shake
  6. @export var shake_duration: float = 0.5    # Duração do shake em segundos
  7.  
  8. var shake_timer: float = 0.0
  9.  
  10. func _input(event: InputEvent) -> void:
  11.     if event.is_action_pressed("ui_sk"):
  12.         start_screen_shake()
  13.  
  14. func start_screen_shake() -> void:
  15.     shake_timer = shake_duration
  16.  
  17. func _process(delta: float) -> void:
  18.     if shake_timer > 0:
  19.         shake_timer -= delta
  20.         # Aplica o shake à câmera
  21.         offset = Vector2(randi_range(-shake_intensity, shake_intensity), randi_range(-shake_intensity, shake_intensity))
  22.     else:
  23.         offset = Vector2.ZERO  # Para o shake quando o timer acabar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement