Detecting wind speed script

I’ve been searching this specific topic for so long but I haven’t managed to find any solution at all. So what I’m trying to archive here is to make a wind speed detector for my game. And with that I would apply an effect to it such as shake effect. What I’m trying to do here is making the shake speed so that when the player move at a high speed, the shakes will start to occur. If anyone could explain me how you would do this in a script, it would be nice if you give me some helps. Thanks!

2 Likes

There’s no such thing as “wind speed” in Roblox(as I am aware of). Perhaps you could use the player character velocity:

--LocalScript inside StarterCharacterScripts(if it's only for local visual effects)
local RunService = game:GetService("RunService")

local Character = script.Parent

local Root = Character:WaitForChild("HumanoidRootPart", 5)
if not Root then warn("HumanoidRootPart wasn't found") return end 

local connection 
connection = RunService.RenderStepped:Connect(function()
	if not Root then 
		connection:Disconnect() 
		return 
	end
	local velocity = Root.Velocity 
	--then you can use the velocity x, y, z to detect speed
	print(velocity)
end)
5 Likes

The way I would go about doing this. Is if you detect the speed the player is going through a local script then have some arguments determining what happens at what speed

Something on the lines of:

local CameraShaking = false

game.Players.LocalPlayer.CharacterAdded:Connect(function(Char)
	
	while Char do
		
		wait()
		
		local Speed = Char.Humanoid.WalkSpeed
		
		
		if Speed > 20 then

			if WindSound.Playing == false then
				WindSound:Play()
			end

			WindSound.Volume = (Speed-19/10)
			
		else
			
			if WindSound.Playing == true then
				WindSound:Stop()
			end

			
		end

		if Speed > 30 and CameraShaking == false then

			CameraShaking = true
			CameraEffects()

		end	

	end
	
end)
2 Likes

WalkSpeed isn’t related to movement, your script will detect how fast a character is able to move instead(for example if they are idle but have a WalkSpeed of 100 your script will misbehave).

2 Likes

For some reason I was thinking the Player would always be moving. But even still there was a lot wrong with the above.

Ignore my previous post

1 Like

Thanks! I mean yeah you’re right. I shouldn’t have said the wind at all but thank you!

1 Like

Also I have one question for you. So every object in the game like the part object. Does it has its own velocity to it?

Every BasePart(Part, MeshPart etc.) has it’s own velocity, although If a part is anchored it’s velocity wont change, which means you want to use velocity for physics based movement(such as a player moving) not anchored tweening and such(although if you manually set the velocity of an anchored part it never goes down which can be helpful for stuff like conveyor belts).

I never know this at all since I started developing my project but thank you for that. And also what about the magnitude thing? Some people use it to detect speed movement for their model. I don’t understand how they do that and it’s a bit complicated. First what I’ve seen were they used like a bodythrust(the physic function that controls car’s wheels to move forward) as detecting a speed movement. Then, they implemented it with sound volume of the wind which means if the car’s wheel is spinning faster, the more louder the sound produces. And yeah it’s kinda complicated

Honestly I consider myself unexperienced with physics based scripting, although I think magnitude is used as a fast way to calculate the distance between two objects(perhaps those users use some kind of velocity formula to detect the amount of distance travelled in a small amount of time) and it may be a better solution as it returns a single value, example:

local old = Root.Position
local connection 
connection = RunService.RenderStepped:Connect(function()
	if not Root then 
		connection:Disconnect() 
		return 
	end
	local velocity = (Root.Position-old).Magnitude*100
	old = Root.Position
	--returns a single value which makes it easier to use(although it will also count situations like free falling)
	print(velocity)
end)

After 6 days, I managed to find a working solution(it gets the current player WalkSpeed using pythagorean theorem)

--LocalScript inside StarterCharacterScripts
local Character = script.Parent

local Root = Character:WaitForChild("HumanoidRootPart", 5)
if not Root then warn("HumanoidRootPart wasn't found") return end 

--math.abs returns the absolute value of a number
local abs = math.abs 

while task.wait() do 
	if not Root then break end 

	--get the HumanoidRootPart Velocity
	local velocity = Root.Velocity
	
	--Apply pythagorean theorem 
	local total = math.sqrt(abs(velocity.X)^2+abs(velocity.Z)^2)

	--round speed
	local speed = math.round(total)
	print(speed)
end
1 Like