Wind Shake: High performance wind effect for leaves and foliage

That would require hundreds or thousands of raycasts every update, so no. That would be terrible for performance.

2 Likes

Boatbomber back at it again!

Love the script, this will help alot of people trying to make their terrain more alive!

2 Likes

Amazing! Makes the game look so much more realistic. Great job :+1:

3 Likes

This looks amazing. It will be very useful for my upcoming open world game. It just makes the game 100x better visually.

4 Likes

Amazing! Just one question. For some reason when I hit run, all the leaves move, when I hit play, half the leaves move and the other half doesn’t, when I publish and join the game, nothing moves at all. (Used almost the same script as you used in the example.)

local WIND_DIRECTION = Vector3.new(1,0,0)
local WIND_SPEED = 15
local WIND_POWER = 1

local WindShake = require(script.WindShake)

WindShake:Init()
WindShake:SetDefaultSettings({
	Speed = WIND_SPEED;
	Direction = WIND_DIRECTION;
	Power = WIND_POWER;
})


for _, Tree in pairs(workspace:GetChildren()) do
	if Tree.Name == "Tree" then
        for _, Leaf in pairs(Tree:GetDescendants()) do
            if Leaf.Name == "Leaves 1" or Leaf.Name == "Leaves 2" or Leaf.Name == "Leaves 3" or Leaf.Name == "Leaves 4" or Leaf.Name == "Leaf" then
                WindShake:AddObjectShake(Leaf)
        end
    end
	end
end

Is there something I am doing wrong?

4 Likes

Only leaves nearby the camera in workspace will be animated. If you’re using a local script this is the player’s camera, if you’re using a server script, don’t.

5 Likes

A couple of users in my game are seeing this exact same problem, while I am not. Wondering if there’s an engine bug happening behind the scenes here. What are your specs?

2 Likes

CPU is a Ryzen 7 3700X and GPU is a GTX 1660.

1 Like

Massive Update!

This update is courtesy of the wonderful @Maximum_ADHD!

  • Automatic shake application via CollectionService
  • Object shake settings exposed via Attributes
  • Added WindShake:RemoveObjectShake()
  • Motion interpolation for smoother shaking
  • Minor patches and internal abstractions
  • Full backwards compatibility

This update is really important. By exposing the shake data through CollectionService and Attributes, environment artists on your team with no programming knowledge can now implement and alter the shake of objects without ever opening your script! They just add the tag to the object and then set the attributes!

Motion interpolation for smoother shaking is a decoupling of the calculations and the positioning. The motion will occur at full FPS (which is a minor performance loss, but significant visual improvement) while the actual calculation of the wind happens at 30 Hz (or whatever you set it to). The noise math happens at 30 Hz and in between those steps, the leaf lerps to the calculated position. It’s a very nice balance of performance and visuals.

The update is backwards compatible- you can just insert the new module in place of the old one and be on your merry way. However, there are a couple things that will change and are worth noting:

  • By default, objects tagged with WindShake in CollectionService will now be given shake automatically. You can change this tag to anything you want (COLLECTION_TAG variable in the module) to suit your game and avoid conflicts if necessary.
  • Objects with a shake will now have Attributes automatically added that correspond to their shake settings. Altering those Attributes will alter the shake, so if you had WindPower, WindSpeed, or WindDirection attributes relating to something else they will now conflict. Highly unlikely for you to have those attributes prior to this, so I doubt this is an issue.

Those differences will likely not cause any issues, so it should be a piece of cake to switch over.

The old APIs of WindShake:UpdateObjectSettings() and WindShake:SetDefaultSettings() still exist and will function just fine- however they are considered deprecated in favor of just altering the object’s relevant Attributes instead (the default settings are the attributes of the WindShake modulescript itself). This way, you can change the shake of an object without needing to even require the WindShake module from that particular script.

37 Likes

Prepending the attributes with “Wind” would avoid conflict and make more sense as property names.

5 Likes

That’s a good point. It would be extremely easy to do so, but then it leads to a odd disconnect between the names in the dictionary and the names in the attributes.
You’d pass a dictionary to UpdateObjectShake with Direction as a key and it affects an attribute named WindDirection. That works, but it just seems icky to me.
I’d either have to accept that key names aren’t the same (which can lead to confusion and mistakes) or I’d have to break backwards compatibility by making the dictionary key names start with “Wind”. Or I could make it handle both types of keys in the dictionary, but that’s even worse for maintainability and confusion factor.
What do you suggest?

(Edit: I’d also like to see if anyone actually has an issue with the attribute names. It’s a possible conflict, which is why I mentioned it, but unlikely. I doubt anyone has a Power attribute on a grass mesh prior to this.)

Edit: Solved.

See next reply.

3 Likes

Update:

Suggested by @AstroCode

Power, Speed, and Direction are now deprecated in favor of WindSpeed, WindPower, and WindDirection.

These new names are more descriptive and less likely to conflict with other systems.
The old names will be supported through the dictionary API (until the next large update) but the Attributes will not support the old name, as the entire point of this was to avoid using generic Attributes.

image


Edit: Support for these deprecated names has been removed as of 4/6/2021

8 Likes

One of the scripts should have a line where it inserts screengui, just delete the whole line and it should be fixed. (I think it was wind controller, that it was in.) Sorry for being slightly late.

2 Likes

Wow. This just looks really gorgeous. When coupled with the realistic Roblox terrain grass, PBR materials and realistic lighting it will make games look really realistic. Nice job! :+1:

1 Like

Looks amazing!
Would love to use it for a game I’m making for my group. Only problem is I don’t understand how it works. I have no experience with any scripts, open sourcing, what a module is etc.
Could you possibly make a tutorial on how to use it for people (like me) who have no idea how to use it?

4 Likes

really awesome effect! but i have ran into an issue.

whenever i try to use my own trees, the effect doesn’t apply to them. i took a snippet of the demo and put it into my game where i had trees i made prior.

screenshots and videos (sorry for laggy videos, my computer isn’t good)

what happens when i playtest
https://gyazo.com/4a391f8d4d8cb5a5587a307bdf0e847a

what the tree looks like in explorer (OakTree is mine)
https://gyazo.com/801a536665633c87512012b7de8d60ad

anyone have a solution?

4 Likes

Great module! But I’m struggling to get it to work for my game I the module model I don’t know how to configure it for my game I read the API but I can’t configure it.
Thank you!

2 Likes

How do i add a object to make it shake? Im a very beginner scripter so i dont know how.

1 Like

Glad this popped up! Will definitely use it.

1 Like

Use the Tag Editor to add a “WindShake” tag on the baseparts that you want moving

2 Likes