Screen shake in 2D but with a specified direction not random

Godot Version

4.3 stable

Question

I was trying too make camera shake but every tutorial that I found used random nubers for shaking and I was looking for a way to shake with a direction.

you can use animation player node instead

1 Like

Yeah, instead of using the random number choose your interpolation target before hand.

So let’s say your hero gets hit from the right and you want the screen to jut left to emphasize the impact:

var tween = get_tree().create_tween()
var jut_left = Vector2(-20, 0)
tween.tween_property($cam2d, "offset", jut_left, 0.25)
tween.tween_property($cam2d, "offset", Vector2(), 0.25)

Or your hero can get hit from any direction and want to jut out from the incoming damage:

var jut = target.position.direction_to(position) * JUT_POWER
tween.tween_property($cam2d, "offset", jut, 0.25)
tween.tween_property($cam2d, "offset", Vector2(), 0.25)

The code probably isn’t 100% correct just typed it out. Hopefully you can extrapolate from the tutorials you have read and this example code to create your own function.

Good luck and happy hacking!

1 Like

@zoopira That’s exactly what I was going to say! :rofl:

1 Like