Godot相机抖动

Posted 张学徒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Godot相机抖动相关的知识,希望对你有一定的参考价值。

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()

以上是关于Godot相机抖动的主要内容,如果未能解决你的问题,请参考以下文章

Opencv算法在移动/抖动相机中检测移动车辆

相机跟随刚体抖动每隔几秒与背景对象

python 2D相机抖动扩展

CinemachineFreelook相机鬼畜抖动的解决方法

由于 Time.deltaTime,C#/Unity 相机跟随抖动

防止在抖动中调用相机活动后重置FormFieldText