I have a viewportframe that has an arrow mesh indicating wind direction (Vector3) relative to the camera. I use renderstep to update it smoothly, but I want to make the code fire only when the camera is actually moving, so it doesn't run when it's not needed.
Is there a way to know when a camera starts or stops moving?
I tried looking for UserInputService, the camera Object, without results.
Guess I found out a way. Sorry for the post.
You can use UserInputService.InputBegan and InputEnded to check if the player is holding the mousebutton2 (right one):
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local rightclick = false |
03 | UIS.InputBegan:connect( function (input,process) |
04 | if not process and input.UserInputType = = Enum.UserInputType.MouseButton 2 then |
05 | rightclick = true |
06 | end |
07 | end ) |
08 | UIS.InputEnded:connect( function (input,process) |
09 | if input.UserInputType = = Enum.UserInputType.MouseButton 2 then |
10 | rightclick = false |
11 | end |
12 | end ) |
After this you use UserInputService.InputChanged to check if the player moved the mouse and then, if he is holding the mousebutton2, do the code:
1 | UIS.InputChanged:Connect( function (input,process) |
2 | if rightclick = = true and input.UserInputType = = Enum.UserInputType.MouseMovement then |
3 | --code here |
4 | end |
5 | end ) |