How to detect if a player is done moving the camera

I’m currently trying to detect when a player is done moving their camera but I don’t have a single clue on what will I depend on (User Input? Camera? Etc.) Can anyone give a method to detect when a player’s camera is done moving.

1 Like

Roblox API can help.

workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function()

end)

Fires every time the camera’s CFrame is changed, which in this case is the player’s input.

5 Likes

I’m actually using this at the moment, but I need the CFrame of the camera after the player moves the camera, not every frame the camera is moved.

1 Like

I guess if you want to see when the player no longer moves the camera you can use GetPanSpeed() and then establish afk time. This is just theory otherwise I have no idea.

3 Likes

Well, you can use it still.

workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(function(cframe)
           delay(5, function()
                     if cframe == workspace.CurrentCamera.CFrame then
                              stopped = true
                     end
           end)
end)
4 Likes

Ehh, this wouldn’t be beneficial if the player continues to move their character which would just keep changing the camera cframe. I’d suggest using GetPanSpeed() instead to see if they’re manually moving the camera.

4 Likes

@Ancient_Orange Just when I read the wiki

2 Likes

This could be the most inefficient way of doing it but for some touchy events, I use a “timeout” variable.

local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local Timeout = 0

function CFrameUpdate()
	Timeout = 0.1
end

function MoveCheck()
	Timeout = Timeout - 0.1
end

RunService.Heartbeat:Connect(MoveCheck)
Camera:GetPropertyChangedSignal("CFrame"):Connect(CFrameUpdate)

while wait() do
	if Timeout <= 0 then
		print("Camera is not moving")
		Timeout = 0 --// Not needed but :shrug:
	else
		print("Camera is moving")
	end
end
2 Likes

I’m not sure if I understand what you’re trying to achieve. I’m gonna guess you want the CFrame before and after they move the mouse in which case you can do something like the following:

local moving = false -- Will debounce to make sure we don't spam the event
local MovedCamera = Instance.new("BindableEvent") -- The event to fire
local CFrameChanged = workspace.CurrentCamera:GetPropertyChangedSignal("CFrame") -- An event which will fire when the CFrame of the camera changes
CFrameChanged:Connect(function()
    if moving then -- Camera is already moving
        return
    end
    moving = true -- The camera is now moving
    local before = workspace.CurrentCamera.CFrame -- The position of their camera before it started moving
    local lastFrame = before -- The position of the camera on the last frame
    CFrameChanged:Wait() -- Wait for the camera position to change (You may need to change this to use positionRunService.Heartbeat or RunService.RenderStepped instead if the CFrame 
    while workspace.CurrentCamera.CFrame.LookVector ~= lastFrame.LookVector do -- Check if the camera isn't moving. Can remove LookVector to also check position.
        lastFrame = workspace.CurrentCamera.CFrame -- Set the 
        CFrameChanged:Wait() -- Also might need changing
    end
    moving = false -- The camera isn't moving anymore
    local after = workspace.CurrentCamera.CFrame -- The final position of their camera
    MovedCamera:Fire(before, after) -- Fire the event
end)
MovedCamera.Event:Connect(function(before, after)
    -- Stuff!
end)

Basically what I do is wait for the camera’s position to be equal to the last frame (aka the camera stopped moving) and once it isn’t moving I fire an event.

3 Likes