Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DYNAMIC WIND SIMULATOR v1.00 --
- -- Simulates realistic GlobalWinds via randomization
- local minSpeed = 10 -- Minimum wind speed in studs per second
- local maxSpeed = 75 -- Maximum wind speed in studs per second
- local minAngle = 0 -- Minimum wind direction angle in degrees
- local maxAngle = 360 -- Maximum wind direction angle in degrees
- local minInterval = math.random(5, 20) -- Minimum interval in seconds (Change to fixed value if needed)
- local maxInterval = math.random(30, 120) -- Maximum interval in seconds (Change to fixed value if needed)
- local transitionDuration = 7.5 -- Transition length between randomizing Speed & Direction in seconds
- -- MAIN FUNCTIONS (Only modify when you know what you're doing!) --
- local workspace = game:GetService("Workspace")
- local rng = Random.new()
- local function linearInterpolation(startValue, endValue, progress)
- local difference = endValue - startValue
- local interpolatedValue = startValue + difference * progress
- return interpolatedValue
- end
- local function vectorInterpolation(startVector, endVector, progress)
- local x = linearInterpolation(startVector.X, endVector.X, progress)
- local y = linearInterpolation(startVector.Y, endVector.Y, progress)
- local z = linearInterpolation(startVector.Z, endVector.Z, progress)
- local interpolatedVector = Vector3.new(x, y, z)
- return interpolatedVector
- end
- local function randomizeWind()
- local speed = rng:NextNumber(minSpeed, maxSpeed)
- local angle = rng:NextNumber(minAngle, maxAngle)
- local radian = math.rad(angle)
- local vector = Vector3.new(math.cos(radian) * speed, 0, math.sin(radian) * speed)
- return speed, vector
- end
- local function transitionWind()
- local currentSpeed = workspace.GlobalWind.Magnitude
- local currentVector = workspace.GlobalWind
- local targetSpeed, targetVector = randomizeWind()
- print("Initial speed: " .. math.floor(currentSpeed * 10 + 0.5) / 10 .. " studs/second")
- print("Initial direction: " .. math.floor(math.deg(math.atan2(currentVector.Z, currentVector.X)) * 10 + 0.5) / 10 .. " degrees")
- local elapsedTime = 0
- local connection
- local function updateWind()
- elapsedTime = elapsedTime + game:GetService("RunService").RenderStepped:Wait()
- if elapsedTime < transitionDuration then
- local progress = elapsedTime / transitionDuration
- local interpolatedVector = vectorInterpolation(currentVector, targetVector, progress)
- workspace.GlobalWind = interpolatedVector
- else
- workspace.GlobalWind = targetVector
- print("Final speed: " .. math.floor(targetSpeed * 10 + 0.5) / 10 .. " studs/second")
- print("Final direction: " .. math.floor(math.deg(math.atan2(targetVector.Z, targetVector.X)) * 10 + 0.5) / 10 .. " degrees")
- connection:Disconnect()
- end
- end
- connection = game:GetService("RunService").RenderStepped:Connect(updateWind)
- end
- local function setRandomInterval()
- local interval = rng:NextNumber(minInterval, maxInterval)
- local roundedInterval = math.floor(interval * 10 + 0.5) / 10
- print("The wind will change in " .. roundedInterval .. " seconds")
- delay(interval, transitionWind)
- delay(interval, setRandomInterval)
- end
- setRandomInterval()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement