Wind Shake: High performance wind effect for leaves and foliage

I have added a simple function to fix this for me. Will be pinning soon. @boatbomber with your permission of course.

https://gyazo.com/2d2c50fed485c145e21c7fde0c216196

1 Like

Update: Pivot Points

Suggested by @Maximum_ADHD and @Manelin

Roblox recently added a new feature, Pivot Points. You can read about it here:

I’ve updated WindShake to support the new BasePart.PivotOffset property. You can set any arbitrary pivot point for your part, and WindShake will rotate the part from your defined pivot point.

Prior to this update, all shaking was done from the center of the objects volume. This looked decent in most cases, but could feel rather “floaty” in cases where you’d expect the object to shake from a pivot point near the base- like a leaf shaking from its stem or dangling moss shaking from its base. This feature allows you to make your foliage seem more grounded and rotate from a realistic point.


Update: Rotation Improvement

Previously, objects only rotated in a single direction- they waved back and forth along this plane. This update fixes that by seeding each axis differently in order to give them individual motions for more flowing motion.


Here’s a demonstration of these two features. See how the trunk now rotates from the base, instead of the center? How the objects rotate on all axis, instead of just wiggling back and forth diagonally?
Looks much better.

45 Likes

Update: Performance Improvements!

This module was initially extremely performant, handling tens of thousands of objects at 400+ FPS. However, as more features were added over time, performance took a noticeable hit. There were some users who used older versions of WindShake due to performance implications.

Prior to this performance update, my machine ran a stress test at ~140 FPS. After these performance improvements, it ran at ~230 FPS.

I started by optimizing the calculations, removing metatable usage and minimizing attribute calls. Then @pobammer helped with a more optimized version of the octree module.
Those changes did help squeeze out some more milliseconds, as shown in this stacked bar chart.

I still felt it wasn’t enough. Once the computation was as efficient as it could reasonably be, I then reduced the amount of times that work is done. WindShake would calculate the object targets at 30Hz, and visually set the objects every single frame with linear interpolation. Setting every frame was simply unneeded work. Having leaves update at 150Hz is wasteful and lowers the performance for no real gain. So I added a limiter on the visual setter, and that was enough to boost performance back up to an acceptable level (230FPS). Visuals update at 45Hz by default, but can be configured within the module.

All in all, these changes really boost the performance (especially in cases with tons of objects) and I recommend updating to this latest version!

24 Likes

Hey, can you help me? I can’t get it to work. I tried both on the server and on the client. Basically I tagged all the leaves by adding an attribute into them and then:

for _, Leaf in ipairs(workspace.Map:GetDescendants()) do
	if Leaf:IsA("BasePart") and Leaf:GetAttribute("WindShake") == true then
		WindShake:AddObjectShake(Leaf); -- I tried printing the parts' names and they printed so the way I tagged with attributes isn't the problem
	end;
end;
WindShake:Init();

But they aren’t working for some reason. Do they have to be unanchored? Also can it be used on the client? Thanks in advance.

2 Likes

Try using :Init() before the ipairs iteration part.

Damn, it was that easy. Thanks dawg, it works perfectly fine now.

2 Likes

Now you just gotta make the leaves move with the top of the top of the trunk!

1 Like

Hey man. I wonder why you hard-coded the range value?
It’s a pretty important variable. I was looking for it since I have a big scene.

Because it’s a footgun and I didn’t want people to alter it without knowing what they’re doing. A bigger range mean performance drops, and it’s not linear- it drops down fast.

You can change it if you like, something like this:

Search(cameraCF.Position + (cameraCF.LookVector * (Range-5)), Range)
3 Likes

Quick question though ive been using this plugin and ive noticed that it doesnt have the little wind effects how can i add that?

Details about the lines was already stated in the post.

4 Likes

Opps sorry! I should have read the full post

2 Likes

6154aae1c3ab296bafe7d45b40ba3adb

If I lower these, will it help at all with any sort of lag?

Yes, although it will make the leaf motion seem choppier.

2 Likes

I used the model plugin of this, and it is working well and smoothly in the studio. However, in the game itself, the parts tagged into the WindShake are moving very poorly, they move in a choppy way. I made sure it wasn’t in my connection or my device. I also changed the Hz lower and above, but it still works very poorly. Here is the game to check out the performance yourself: MODEL TESTING - Roblox

UPDATE: IT works much better now! I applied the code into a LocalScript, and it works as expected now. Much more smooth and not choppy. Would totally recommend!

1 Like

you could disable the wind streak feature if you can detect if youre indoors

1 Like

Is there a way to “restart” the wind lines instead of calling the module function for it to just stack up the wind lines

This is a great model, however when I use this on my ghibli trees, they just get out of position, and I can’t turn my leaves cancollide off since it wont work.

1 Like

You shouldn’t be shaking collidable objects anyway since the physics of moving so many objects like that can lag

1 Like

That’s why I’m trying to turn cancollide to false but they just fall of the map.