Wave Cubes

Someone just asked on Unreal Engine 4 Developers' Community on Facebook how to make a surface of moving cubes.

After a quick discussion we determined that the effect can just be applied to the material shader of each cube rather than moving each one though the tick. If collision is needed than this technique doesn't work since its not actually moving the cubes.

First we need to create a plane of cubes. 21x21 cubes should be enough.

Blueprint spawning actor

Keep in mind if you put large values in loops on the construction script of Blueprints you could be waiting a long time or crash the engine: start with small values and push it later. Moving this part to C++ would definitely help but we should be fine for now.

For the material shader we must first get the world location of each pixel in space. Since our cube size is 10x10 (you will have to change this depending on your cube size) we will divide that by 10 and then round each of the values. This will give us nice 10 unit steps of values later.

stepped values in 3d space

We didn't do anything to keep the position of the actor Blueprint that spawned the cubes at 10 unit increments so when you position that actor in the world make sure its a factor of 10 on both the x and y axis. i.e. 100, 0, 0 or -20, 50, 30.

You can play around with the noise values but these seems to work well. After the noise node multiply it by 100 to get some dramatic movement and plug it into a Float3 vector. We only want the Z channel to move so leave x and y blank. Plug that into the World Position Offset. This will then offset each vector of the cubeaccording to the amount generated by the 3d noise node. Color can be connected too for a more visible effect in case the position offsets aren't multiplied enough.

the 3d noise node

You can then save the material and apply it to the static mesh instance of our plane of cubes spawning actor Blueprint.

If all goes well it should output something like this. You might want to scale the cubes down slightly so it doesn't overlap any vertices.

back to the blueprint actor to see our progress

Ahhh but the cubes aren't moving just yet, they are still static but offset. Well, go back to the material and add this on the x or y channel of that Float3 before the noise. This will add a value in the form of time and shift the noise in that direction.

Motion nodes

AND THAT IS IT! Feel free to post comments, questions, or suggestions. I hope you enjoyed this exercise in UE4 materials.

Continue to part 2