Advertisement
1m1m0

Dynamic Winds v1.0.0

Jan 1st, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | Source Code | 0 0
  1. -- DYNAMIC WIND SIMULATOR v1.00 --
  2. -- Simulates realistic GlobalWinds via randomization
  3.  
  4. local minSpeed = 10 -- Minimum wind speed in studs per second
  5. local maxSpeed = 75 -- Maximum wind speed in studs per second
  6. local minAngle = 0 -- Minimum wind direction angle in degrees
  7. local maxAngle = 360 -- Maximum wind direction angle in degrees
  8. local minInterval = math.random(5, 20) -- Minimum interval in seconds (Change to fixed value if needed)
  9. local maxInterval = math.random(30, 120) -- Maximum interval in seconds (Change to fixed value if needed)
  10. local transitionDuration = 7.5 -- Transition length between randomizing Speed & Direction in seconds
  11.  
  12. -- MAIN FUNCTIONS (Only modify when you know what you're doing!) --
  13.  
  14. local workspace = game:GetService("Workspace")
  15.  
  16. local rng = Random.new()
  17.  
  18. local function linearInterpolation(startValue, endValue, progress)
  19.     local difference = endValue - startValue
  20.     local interpolatedValue = startValue + difference * progress
  21.     return interpolatedValue
  22. end
  23.  
  24. local function vectorInterpolation(startVector, endVector, progress)
  25.     local x = linearInterpolation(startVector.X, endVector.X, progress)
  26.     local y = linearInterpolation(startVector.Y, endVector.Y, progress)
  27.     local z = linearInterpolation(startVector.Z, endVector.Z, progress)
  28.     local interpolatedVector = Vector3.new(x, y, z)
  29.     return interpolatedVector
  30. end
  31.  
  32. local function randomizeWind()
  33.     local speed = rng:NextNumber(minSpeed, maxSpeed)
  34.     local angle = rng:NextNumber(minAngle, maxAngle)
  35.     local radian = math.rad(angle)
  36.     local vector = Vector3.new(math.cos(radian) * speed, 0, math.sin(radian) * speed)
  37.     return speed, vector
  38. end
  39.  
  40. local function transitionWind()
  41.     local currentSpeed = workspace.GlobalWind.Magnitude
  42.     local currentVector = workspace.GlobalWind
  43.     local targetSpeed, targetVector = randomizeWind()
  44.  
  45.     print("Initial speed: " .. math.floor(currentSpeed * 10 + 0.5) / 10 .. " studs/second")
  46.     print("Initial direction: " .. math.floor(math.deg(math.atan2(currentVector.Z, currentVector.X)) * 10 + 0.5) / 10 .. " degrees")
  47.  
  48.     local elapsedTime = 0
  49.     local connection
  50.  
  51.     local function updateWind()
  52.         elapsedTime = elapsedTime + game:GetService("RunService").RenderStepped:Wait()
  53.         if elapsedTime < transitionDuration then
  54.             local progress = elapsedTime / transitionDuration
  55.             local interpolatedVector = vectorInterpolation(currentVector, targetVector, progress)
  56.             workspace.GlobalWind = interpolatedVector
  57.         else
  58.             workspace.GlobalWind = targetVector
  59.            
  60.             print("Final speed: " .. math.floor(targetSpeed * 10 + 0.5) / 10 .. " studs/second")
  61.             print("Final direction: " .. math.floor(math.deg(math.atan2(targetVector.Z, targetVector.X)) * 10 + 0.5) / 10 .. " degrees")
  62.  
  63.             connection:Disconnect()
  64.         end
  65.     end
  66.  
  67.     connection = game:GetService("RunService").RenderStepped:Connect(updateWind)
  68. end
  69.  
  70. local function setRandomInterval()
  71.     local interval = rng:NextNumber(minInterval, maxInterval)
  72.     local roundedInterval = math.floor(interval * 10 + 0.5) / 10
  73.  
  74.     print("The wind will change in " .. roundedInterval .. " seconds")
  75.  
  76.     delay(interval, transitionWind)
  77.     delay(interval, setRandomInterval)
  78. end
  79.  
  80. setRandomInterval()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement