It looks like you're new here. If you want to get involved, click one of these buttons!

3absh
Member, PRO Posts: **575**

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.

0

## Comments

575Note:

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

5,593@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.

www.Jamie-Cross.net ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad

1,614So 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!

2,849Here is a camera shake that might be close.

5,593@RThurman, that's nice.

www.Jamie-Cross.net ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad

575Wow, 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.

575This 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.

575Same sample but with a smaller jolt at the end

2,849Try 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.

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

2,849@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".

2,849@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

523excellent