I am working on a top-down, tile-based game (think 2D RPG). However, I would like to have trees that sway in the wind and shake a little if the player bumps into them!

How should I approach this? Is it achievable with trees that are composed of tiles and part of a tilemap?

Or should I exclude my trees from the tilemap and turn them into game objects instead?

If I were to turn them into separate game objects, would I then manually tweak their rotation/position to achieve the sway and shake, or is there some form of shader I can use?

  • 1
    \$\begingroup\$ Take a look at docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@1.6/… if this is enough for your need \$\endgroup\$ – Zibelas Dec 25 '20 at 12:32
  • \$\begingroup\$ Thanks, I'm familiar with Animated Tiles and the 2D Extras Package. But with those, I would need to create sprite animations and then play them on the events. My trees also are more than a single tile high and wide, so that's a problem. My question is if there is a way to achieve this programmatically, without having to create additional tree sprite frames, and including more/random variety of the animation? \$\endgroup\$ – Ben Dec 25 '20 at 12:37
  • \$\begingroup\$ If you want to go with a shader, there are some easy ways how to achieve the effect. What is best for you depends as well how your game works. YouTube has more than one shader solution if you want to do it that way. youtu.be/aKzUsxLJ4SU And of course you can have different sized tiles in your game. Your tree trunk could be 2x1 with a 3x3 secondary animated crown \$\endgroup\$ – Zibelas Dec 25 '20 at 12:45
  • \$\begingroup\$ Thanks, will the shader from the video be suitable for pixel art? \$\endgroup\$ – Ben Dec 25 '20 at 12:50
  • 1
    \$\begingroup\$ That detail belongs in your question. Try including a screenshot of your trees, or a mock-up of what you want a swaying frame to look like. \$\endgroup\$ – DMGregory Dec 25 '20 at 13:02

Your Answer

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

Browse other questions tagged or ask your own question.