That would require hundreds or thousands of raycasts every update, so no. That would be terrible for performance.
Boatbomber back at it again!
Love the script, this will help alot of people trying to make their terrain more alive!
Amazing! Makes the game look so much more realistic. Great job
This looks amazing. It will be very useful for my upcoming open world game. It just makes the game 100x better visually.
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?
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.
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?
CPU is a Ryzen 7 3700X and GPU is a GTX 1660.
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.
Prepending the attributes with âWindâ would avoid conflict and make more sense as property names.
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.
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.
Edit: Support for these deprecated names has been removed as of 4/6/2021
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.
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!
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?
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?
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!
How do i add a object to make it shake? Im a very beginner scripter so i dont know how.
Glad this popped up! Will definitely use it.
Use the Tag Editor to add a âWindShakeâ tag on the baseparts that you want moving