Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to detect how fast the camera is rotating??

I will set a function which depends on how fast the camera is rotating each second. But, I've been stuck on this part.

Any help would be Highly Appreciated! Thanks in advance.

2 comments

0

how fast it's moving or rotating?

0

Rotating

1 answer

✓ Accepted answer

Here is a code that prints camera rotation speed and movement speed, difference is that movement speed is not 0 when you are zooming in and out:

local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local currentCamera = Workspace.CurrentCamera

local previousCFrame = currentCamera.CFrame

RunService.RenderStepped:Connect(function()
  local cframe = currentCamera.CFrame
  
  local speed = (previousCFrame.Position - cframe.Position).Magnitude
  local _, rotation = (cframe * previousCFrame:Inverse()):ToAxisAngle()

  print(("Current movement speed of camera: %d"):format(speed))
  print(("Current rotation speed of camera: %d"):format(math.deg(rotation)))
  
  previousCFrame = cframe
end)

To get the movement speed you calculate distance between current camera position and camera position from previous frame, for angle I just stole the code here, since the result was in radians using math.deg I converted it to degrees, it's too hard of a math :o

1 comment

0

Thank you so much!!

This discussion is preserved as it was. New answers, comments, and votes are closed.