How to get direction of GlobalWind?

Hello!

So yesterday when the Wind Beta was announced, I put GlobalWind support into my game.

One of the things i did is make the wind change randomly.

I wanted to add more, but I’m running into a problem.

I want to make this flag pivot in the direction of the wind, but I’m not very experienced with pivoting models.
image
I already set a PrimaryPart and have the model set up to pivot.
How would I go about doing this?

I think it would work like this:

FlagModel:PivotTo(CFrame.new(FlagModel:GetPivot().Position, FlagModel:GetPivot().Position + workspace.GlobalWind))

How it’s supposed to work is that the first parameter in CFrame.new() will be the position that will face to the second parameter.

If adding doesn’t work properly, try substracting, or multiplying.

VV The post below could also work.

Having a PrimaryPart set overrides the WorldPivot.


You would use CFrame.lookAt to get the orientation from the direction and add the current position to it.

local Flag = workspace.Flag

local function UpdateFlag(GlobalWind)
	local Position = Flag:GetPivot().Position
	local Rotation = CFrame.lookAt(Vector3.zero, GlobalWind)
	
	Flag:PivotTo(Rotation + Position)
end

UpdateFlag(workspace.GlobalWind)
workspace:GetPropertyChangedSignal("GlobalWind"):Connect(function()
	UpdateFlag(workspace.GlobalWind)
end)

This assumes your flag has a WorldPivot of (0, 90, 0)

2 Likes

That made it work! Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.