Tree Animator Algorithm + 40 Labeled Trees + Optimized + Simple + FREE + Wind Direction

I have created this system to handle animations of trees. It’s nothing new in terms of functionality, but it’s very optimized and simple to understand. These are all the trees. All of them are animated and located in the workspace of this example.

{
[1] = Maple tree,
[2] = Willow tree,
[3] = Golden Willow tree,
[4] = Birch tree,
[5] = Oak tree,
[6] = Pink Willow tree,
[7] = Banana tree,
[8] = Sakura tree,
[9] = Pine tree,
[10] = Oak tree,
[11] = Pine tree,
[12] = Pine tree,
[13] = Pine tree,
[14] = Pine tree,
[15] = Birch tree,
[16] = Maple tree,
[17] = Oak tree,
[18] = Maidenhair tree,
[19] = Ash tree,
[20] = Douglass Fir tree,
[21] = Broadleaf tree,
[22] = Redwood tree,
[23] = Maple tree,
[24] = Oak tree,
[25] = Wise old tree,
[26] = Beechwood tree,
[27] = tree,
[28] = tree,
[29] = tree,
[30] = Dogwood tree,
[31] = Thick Fir tree,
[32] = Fir Tree,
[33] = Fir Tree,
[34] = Magic Tree,
[35] = Fir tree,
[36] = Oak tree,
[37] = Birch tree,
[38] = Pine tree,
[39] = tall Birch tree,
[40] = short Birch tree
}

All of them have optimized collisions and rendering. I use this library for my own project and I will be testing a client sided version of this code soon. The good news is this code is pretty short so it should be easy to understand! You can copy and paste the server code to the client and it should work the same but provide better responsiveness.

You can copy the public place here to check it out!

I have done testing and this method scales much better than running one script per tree.
One original script runs .1% for one tree for example while this is .5% at 40 trees .
image

This also animates the trunk!
It does so beautifully and optimized by using calculations from the leaves to align the trunk!

--Trunk Animation Module

local treeanim={}
local wind=workspace.GlobalWind
function treeanim.Initialize(Leaves)
	local pos=	Leaves.CFrame
	local T = -99999
	local tall = Leaves.Size.Y / 2
	local rand = (math.random(0,20))/10
	local px5=pos.Position.x/5
	local pz6=pos.Position.z/6
	local function Animate(x,z)
		local x = x and x*.75 or (math.sin(T+(px5))*math.sin(T/9))/4.5
		local z = z and z*.75 or (math.sin(T+(pz6))*math.sin(T/12))/6
		Leaves.CFrame =pos:ToWorldSpace(CFrame.new(x,0,z) * CFrame.Angles((z)/tall, 0,(x)/-tall))* CFrame.Angles(math.rad(wind.Z/tall), 0,math.rad(wind.X/tall))		
		T = T + 0.12
		return Leaves
	end
	return Animate
end
return treeanim

The example code perfectly handles Trees being rendered in an out

I tested different methods of timers and I found that while true do is best for the timing frequency of this system. I really scratch my head considering how to further optimize the code.
Originally I tested versus the original source code and did what I thought would be most efficient but turned out to not be. Then I started over and found some optimizations and that is about all there is to it.

–Features List

  1. Animate all the Trees with one Loop.
  2. Animate The Trunk and Leaves.
  3. 40 Formatted and Optimized Tree Models ready for Game.
  4. The code is short and optimized with a small footprint, compared to other methods.
  5. Supports Wind Direction
3 Likes

If you enjoy this leave a like and check out some of my other open resources I created for the community! (Hint they all work together)
Check out my other popular developer assets I created for the community

The game you linked is not uncopylocked.

1 Like

Sorry about that! I fixed it. it is good to go. :slight_smile:

1 Like

This looks great and much better than what I was using before, the WindShake module.

What I was using before in my game:
https://i.gyazo.com/704160f96ec145fe1f0051bc279a3aee.gif

This module:
https://i.gyazo.com/2597be9677d462b1381ad273d1a78587.gif

I will look forward to if you choose to create an official release of this on the client as although optimized I am still worried about this being on the server.

1 Like