3
\$\begingroup\$

I'm building a top-down strategy 2D game, and i'm stuck animating clouds that will float above the arena, hiding other elements. The effect i want to achieve is something exactly like this:

Clouds

How would i go about implementing it in Unity3D?

\$\endgroup\$
  • \$\begingroup\$ The video doesn't really look like a 2D game. \$\endgroup\$ – Trilarion Sep 15 '17 at 10:39
  • \$\begingroup\$ Yeah, its not a 2D game, but what i'd like to implement is the plane with clouds floating above it. My game has the same perspective as this one, but instead of using 3D models, i'm using sprites for the same visual result. \$\endgroup\$ – Ozymas Sep 15 '17 at 11:12
1
\$\begingroup\$

Most fog of war solutions, probably including the one shown, are shader based. Without knowing much about your project, this is a typical solution in a nutshell:

  1. Create an opaque plane above your map that looks like shadow/fog/clouds or whatever you want to use to obscure what's below. Can be as fancy as you like.

  2. Write a shader that expands the one you were using for the plane but calculates transparency from e.g. a texture passed to it.

  3. Create and update the texture via script and pass it to the shader.

If that approach sounds suitable, this should be a good starting point.

If your game is, like the example, based on a hex (or other non-rectangular) grid, an easier solution might be to create the cloud cover for each cell as a separate object, with a shader using absolute instead of relative texture coordinates so the cells connect and tile seamlessly. This would reduce aliasing at the edges of the concealed area, but might create too much overhead if you have a lot of cells.

PS: Hope I understood your question correctly. If you're just looking for how to make the texture scroll, using Material.SetTextureOffset should suffice in your case. The example you posted looks like it has a semitransparent cloud texture on top of an opaque one, scrolling at different speeds.

\$\endgroup\$
  • \$\begingroup\$ Thanks a lot for the suggestions, Ruther! Yes, you understood perfectly, and this video seems like it will be very useful in my implementation. I'll start working on it later today and will report back with my solution once its completed (and also accept your answer). \$\endgroup\$ – Ozymas Sep 15 '17 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.