How to use Perlin noise for smooth camera shake?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Diet Estus

I have a Camera2D using which I’ve implemented crude camera shake. Currently, I simply change the camera’s offset periodically using a timer.

func OnTimerTimeout():
    offset.x = rand_range(-shift, shift)
    offset.y = rand_range(-shift, shift)

Using this method, the camera jumps discretely every time the offset changes.

I dislike how jarring this is and want the camera to move smoothly from one position to another.

It should be possible to implement this using a Perlin noise function that takes time and a seed as input and returns continuous noise between (0,1).

I’m not sure how to access such a function in Godot, or how I would use it if I had it.

Any ideas?

:bust_in_silhouette: Reply From: markopolo

Simplex noise is a different kind of smooth noise that might be coming soon to Godot. As for how to transform that into smooth camera shake, I highly recommend this talk by Squirrel Eiserloh at GDC. you might also be interested in an add-on I wrote for my own projects based on that talk.

The SimplexNoise pull request was merged and will be in 3.1 :slight_smile:

Calinou | 2018-09-20 07:28