# Morlet wavelet for gunshut camera effect (for PROs only!!)

Member, PRO Posts: 598

I'm trying to make the camera shake in a "Morlet wavelet"

so that when the player shoots camera bounces up, then goes down lesser, then up again lesser then down then stops.

I found this wave but the function I found was kind of confusing to implement here in GS.

https://en.wikipedia.org/wiki/Morlet_wavelet

• Member, PRO Posts: 598

Note:
wave must start at zero (Y axis), then go up from there

• ImagineLabs.rocks Member, BASIC Posts: 5,755

@3absh, I'm sure if @socks were still around he could whip this up, he was a master of sin curves and such. You might try searching the forums if you haven't already. There were a few great tutorials posted about sin curves and GS. They probably wouldn't be this exactly but they might help in understanding how to accomplish something like this.

• Key Master, Head Chef, Executive Chef, Member, PRO Posts: 2,057

So wavelets be a bit more work and I'm not 100% sure how they would impact performance. If I remember right, wavelets are basically summations of various wave functions (wavelets). That form the more complex wave that can't be gotten by a simple function.

So what I can think of is multiplying a bell curve like function (for intensity) with a sine or cosine at the frequency you want.

I googled "trig approximation of bell curve" and got:

f(x) = (1/2pi) * (1 + cos x)

A simplifed sine wave function is:

A * sin(B * x) where A is the amplitude and B is the frequency.

So the expression you're looking for is:

(1 / (2 * 3.1459)) * (1 + cos x)) * sin(b * x)

x should be either time (for shake) or actor.position.x (when you're visualizing the function by making an actor move across the scene).

b should be adjusted to get the right shake frequency you're looking for.

I don't have time right now to whip up an example, but hopefully someone here beats me to it!

Hope that helps!

• Member, Sous Chef, PRO Posts: 2,867

Here is a camera shake that might be close.

• ImagineLabs.rocks Member, BASIC Posts: 5,755
• Member, PRO Posts: 598
edited February 2020

Wow, guys I'm overwhelmed with the fast and AMAZING response.
Thanks @adent42 @RThurman This is EXACTLY what I'm looking for

Now, just to make things a little more challenging & interesting.

My "default" camera isn't really constant. It's moving around in a very subtle x & y sin wave

So I'm trying to make the "Morlet wavelet" ease back into the sin wave instead of zero.

I can use a timer and interpolate for the transition but there will be an ugly jolt effect, and the code I believe won't be as efficient.

• Member, PRO Posts: 598

This is very close to my final result,

I added timers to ease in the transition between the morlet wave and the default camera movement.

Although there is a slight disturbing jolt at the end that I need to get rid of.

• Member, PRO Posts: 598

Same sample but with a smaller jolt at the end

• Member, Sous Chef, PRO Posts: 2,867

Try this one. It combines a bunch of separate functions into one long equation.

Technically, this is not a morlet wavelet. A morlet wave starts small, builds up, and then dissipates (as shown in the graph above). But a gun shot does not build up in the beginning. It just kicks. So.... this equation just simulates the second half of the graph.

• Member, PRO Posts: 598

@RThurman that's awesome, this whole shotting wave function just opened up a wide range of possibilities for me.

• Member, Sous Chef, PRO Posts: 2,867

@jamie_c -- thanks! (We are still using your excellent GameSalad book by the way.)

@3absh -- glad it will work for you! You are correct that using the function can be applied in a wide range of situations. For more information, look up "Hooke's Law".

• Member, Sous Chef, PRO Posts: 2,867

@3absh -- here is a link for a presentation I gave on Hooke's law. It includes a camera shake demo, and some other fun stuff.