Problem with Camera and mouse positions [UNSOLVED]

I’m working on a project, I’m currently making the omen smoke ability from Valorant, I’m almost finished but there’s one tiny problem that I can’t fix, when the smoke takes distance from the player, theres a Camera following the smoke and then the players CurrentCamera is switched to that Camera in question, the CameraType of this Camera is Scriptable and then in result of this, I can track the smoke, changing the Cameras position but not move its orientation using the mouse, so what I’ve done is while it is the players CurrentCamera, I track the mouse movements on the screen and then adjust the orientation of the Camera, my problem is that since the Mouse isn’t locked in the center, it escapes the screen, I’ve tried to lock the mouse in the middle of the screen but then I can’t track its position since it doesn’t change and since Roblox studio doesn’t allow to change a players MouseLocation I’m not sure on how to exactly work this problem out.

local PrimaryCamera = workspace.Camera:Clone()
PrimaryCamera.Parent = PlayerFolder
PrimaryCamera.Name = "PrimaryCamera"

local PlayerMouse = PLR.LocalPlayer:GetMouse()

local function UpdateCamera()
	if not PLR.LocalPlayer.Character then return end
	if workspace.CurrentCamera == PrimaryCamera then return end
	if lastMousePosition then
		local deltaX = (lastMousePosition.X - PlayerMouse.X) * sensitivity
		local deltaY = (PlayerMouse.Y - lastMousePosition.Y) * sensitivity

		local newCFrame = PrimaryCamera.CFrame * CFrame.Angles(0, math.rad(deltaX), 0)
		newCFrame = newCFrame * CFrame.Angles(-math.rad(deltaY), 0, 0)
		PrimaryCamera.CFrame = newCFrame

	end
	lastMousePosition = Vector2.new(PlayerMouse.X, PlayerMouse.Y)
end

Here’s the function of the script that I’m working on, I can send more if needed, I’m looking for a possible alternative way to detect the players mouse movements while in a Scriptable camera, the scriptable camera Is another Camera from the one we can see in this function it’s not the PrimaryCamera

At the end of the video, I’m quickly showing what’s the issue, the mouse gets out of the screen

If anything is needed for me to add to the post, let me know

2 Likes

Maybe lock the mouse at the middle of the screen using this function I just found after a quick Google search? Afterall VALORANT is a FPS, the mouse is always locked in gameplay.

Yes the mouse is always locked, the thing is I need to unlock it since the Camera that tracks the smoke isn’t a Custom Camera but a Scriptable one, but I still want it to be able to be oriented by the player, If I lock the Mouse at the center of the screen, I don’t know how I can track the mouse movements/Allow the player to orient the camera. Im looking for an alternative way, I’ve thought of Locking and Unlocking the camera to see the players mouse movement then locking it then unlocking it etc etc so it can move but doesn’t get out of the screen

1 Like

Here’s the code that handles the smoke’s Camera if that can help.

local function HandleSmokeCamera()
	while true do
		if isInMirrorWorld then
			if IsSmokeAbilityEquipped then
				if currentDistance > defaultDistance then
					
					local direction = (PlacementSmoke.Position - PrimaryCamera.CFrame.Position).unit
					local offsetDistance = defaultDistance
					local smokeCameraPosition = PlacementSmoke.Position - direction * offsetDistance
					local angle = CFrame.new(smokeCameraPosition, PlacementSmoke.Position + Vector3.new(0, 0, 0))
					
					local HRP = PLR.LocalPlayer.Character.PrimaryPart
					PrimaryCamera.CFrame = CFrame.new(HRP.Position, HRP.Position + PrimaryCamera.CFrame.LookVector)

					SmokeCamera.CFrame = angle
					SmokeCamera.CFrame = CFrame.lookAt(SmokeCamera.CFrame.Position, PlacementSmoke.Position)
					workspace.CurrentCamera = SmokeCamera
				else
					SmokeCamera.CFrame = PrimaryCamera.CFrame
					PrimaryCamera.CameraType = Enum.CameraType.Custom
					workspace.CurrentCamera = PrimaryCamera
				end
			end
		end
		task.wait(0.01)
	end
end

Basicly, the “PrimaryCamera”, is the FPS type camera that is locked in first person etc like a regular FPS, but when In the “SmokeCamera” it tracks the players mouse movements and change accordingly the PrimaryCamera’s angle/orientation. A way to fix that problem would be to move back the mouse in the middle of the screen when near or at the edge of the screen but sadly I don’t think roblox allows you to move the players mouse position.

1 Like