Godot 3.4.2
有两种方式
Camera2D 节点控制
Godot 实现镜头晃动震动效果,让场景变得更加惊险刺激吧!
extends Camera2D
export (OpenSimplexNoise) var noise : OpenSimplexNoise
export (float, 0, 1) var trauma : float = 0.5
export (float, 0, 1) var decay : float = 0.6
export var time_scale : float = 100
export var max_x : int = 150
export var max_y : int = 150
export var max_r : int = 25
var __time__ = 0.0
func _process(delta):
__time__ += delta
var shake = pow(trauma, 2)
offset.x = noise.get_noise_3d(__time__ * time_scale, 0, 0) * max_x * shake
offset.y = noise.get_noise_3d(0, __time__ * time_scale, 0) * max_y * shake
rotation_degrees = noise.get_noise_3d(0, 0, __time__ * time_scale) * max_r * shake
if trauma > 0:
trauma = clamp(trauma - (delta * decay), 0, 1)
Tween 节点控制
GODOT ENGINE:屏幕振动效果的实现
extends Tween
class_name CameraShaker
export var camera_path : NodePath
var camera :Camera2D = null
func _ready():
camera = get_node_or_null(camera_path)
func disturb_offset(strength : float):
camera.offset.x = rand_range(-strength,strength)
camera.offset.y = rand_range(-strength,strength)
func shake(strength : float,duration : float = 1.0):
if camera != null:
interpolate_method(self,"disturb_offset",strength,0,duration,Tween.TRANS_SINE,Tween.EASE_OUT,0)
start()
|