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

3absh3absh Member, PRO Posts: 584

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

Comments

  • 3absh3absh Member, PRO Posts: 584

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

  • jamie_cjamie_c ImagineLabs.rocks Member, BASIC Posts: 5,682

    @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.

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 1,818

    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!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,862

    Here is a camera shake that might be close.

  • 3absh3absh Member, PRO Posts: 584
    edited February 13

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

    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.

  • 3absh3absh Member, PRO Posts: 584

    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.

  • 3absh3absh Member, PRO Posts: 584

    Same sample but with a smaller jolt at the end

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,862

    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.

  • 3absh3absh Member, PRO Posts: 584

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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,862

    @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".

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,862

    @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.
    https://forums.gamesalad.com/discussion/comment/560025/#Comment_560025

  • smurftedsmurfted Member, PRO Posts: 523

    excellent

Sign In or Register to comment.