![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | IshiTheArtist |
So I have a character with a stomp ability that gives out a screen shake effect, after this the character gains a movement speed buff and can start to move just when the screen shakes.
Now the problem is not the shake itself, but when the screen shake fades there is a little freeze like shutter.
I suspect it might have something to do with execution order or something.
the screen shake is defined in a script that is attached to a camera2d that follows the character.
having the camera as a child of the target or:
global_position = get_node(target).global_position
…makes no difference.
reducing the shakes power to 0 also does not work.
here the script on the camera
extends Camera2D
export var decay = 0.7
export var max_offset = Vector2(100, 75)
export var max_roll = 0.1
export (NodePath) var target
var trauma = 0.0
var trauma_power = 3
var noise_y = 0
onready var noise = OpenSimplexNoise.new()
func _ready() -> void:
GlobalSignals.connect("animation_thump_finished", self,
"_on_AnimationPlayer_animation_thump_finished")
randomize()
noise.seed = randi()
noise.period = 4
noise.octaves = 2
func _process(delta : float) -> void:
if target:
global_position = get_node(target).global_position
if trauma:
trauma = max(trauma - decay * delta, 0)
shake()
func add_trauma(amount : float) -> void:
trauma = min(trauma + amount, 1.0)
func shake() -> void:
var amount = pow(trauma, trauma_power)
noise_y += 1
rotation = max_roll * amount * noise.get_noise_2d(noise.seed, noise_y)
offset.x = max_offset.x * amount * noise.get_noise_2d(noise.seed*2, noise_y)
offset.y = max_offset.y * amount * noise.get_noise_2d(noise.seed*3, noise_y)
func _on_AnimationPlayer_animation_thump_finished():
add_trauma(3.0)