Download

Shake a mesh

Hi all,

I am looking of a way to make a mesh shake, very much like the camera shake, but applied to one or more static meshes.

But I don’t know what to use in Blueprint, there is nothing apparently as obvious as the camera shake node.

Thank you in advance for your help and advices

Thomas

Hello.

For most things norm is that there are no ready to use solutions, you build them from nodes or C++ functions.

The “code” depends on how you want that mesh to shake. Best way would be to create “BP_shake” blueprint with custom event “Shake IT”.
Then when you want to shake all (or some of them) shakable blueprints, you do “get all actors of class” then “for each array element” on resulting array.
Then you call “shake it” for every actor in loop. That is how you shake them all.

Because shaking is not instant action, you need those events and blueprints. And this is how you shake them:

When you call “shake it” event, your shakable actor which was called should get “current game seconds” value, add how long it wants to shake, and remember result.
Then in that actor in “event tick” event you should randomly pick vector in some range (will describe below some ways) and apply that vector to “relative location” for mesh component that is visible mesh in “shakable blueprint”.
To check if it is still shaking or not compare “current game seconds” with value you stored. When current time is greater set relative location of mesh component to 0,0,0.
This also needs some additional check so that resetting to 0,0,0 does not happen every tick, but just once when actor should stop shaking. So some additional boolean variable and check are needed.

Now how to get nice random values:
You can make [0,0,1] vector, random rotatior, and random float in range.
Then rotate that 0,0,1 vector by random, rotator, and multiply by that float variable.
Result should be some location on sphere surface. This is much nicer than just random location.
It also has additional benefit: you can rotate your mesh by same random rotator if you want it always face outside direction.

Thank you Nawrot. I think I don’t know enough of blueprint to fully understand the process or what to do, but thank you for taking the time

Try something like this for example.

I ran off even tick, but you could make this via a Customer Event or Function.

https://youtube.com/watch?v=_jeC_bOUTRc

Narg

Thanks Narghile, I’ll try that. (it took me some time to realise that was not you talking, very funny ;))

cheers

DOH! normally stop tv while while I record. Sorry

Narg

Hi Narghile,

is there anyway that you could share that blueprint with me please? Because I am trying to make sens of it but I am lost very quickly. Thank you very much :slight_smile:

I will break it down

1st) Ignore sequence.

On event begin play. Set your Pitch (New Var)/ Yaw (New var0) / Roll (New Var1) of the mesh into their own Variables.

Capture.JPG

As I said I am using event tick, but this could be a function or a custom event.

Get 3 random float in range (I did use integers, but I would change them to floats) , I used -5 to +5. Then I add these to the variables you set off begin event play (New var/ New var0 / New var1).

Make a rot of that and then set the world rotation of the mesh.

I put a .1 delay in it so it does not go completely nuts.

Capture.JPG

Hope this helps.

Narg

Hi,

thank you for your time.
I am stuck right at the beginning because I can’t find the GertWorldLocation like yours, with 3 entires, so I can connect them to the 3 variables. The rest seems ok, but this one I can’t get it.

Thank you in advance

Thomase9fdcdbab57c2c0b895423da9dd84cfe0219d287.jpeg

Actually it is already shaking like that (so I don’t know if I need to change anything).
But it move to 0.0.0 in the world and does not stay where I placed it.

You have it, break the purple node.

Right click on it and you should be able to split.

Narg

Fantastic. Much appreciated :slight_smile:

Hope it works they way you want.

Should not have an issue with moving around

Narg

Yes thanks, that was me who placed a wrong node.

cheers

Hello, any way of making this with the position? and can it be smoothed in between frames?