0 votes

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)
Godot version 3.2.3
in Engine by (20 points)

2 Answers

0 votes

I realised like 10 seconds after posting this, using physicsprocess(delta) instead of _process(delta) seems to fix it. Even though the camera process mode is set to idle and switching it to physics makes the shutter reappear.

by (20 points)
0 votes

Another way you can do this is by using AnimationPlayer and Tween. If this is walking bobbing with fixed distance then you can use AnimationPlayer. If this is explosion, then use tween

by (378 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.