How to modify this script so It can "shift" the camera towards the mouse to set limits

So I was wondering how I could make the camera, for my top-down Side project, to shift towards the cursor, but not shift too much so it goes on for infinite or so.

local player = game.Players.LocalPlayer

local function UpdateCamera()
	local char = player.Character
	if not char then return end

	local root = char:FindFirstChild("HumanoidRootPart")
	if not root then return end

	workspace.CurrentCamera.CFrame = CFrame.Angles(math.rad(-90), 0, 0) *, 0, 25) + root.Position

game:GetService("RunService"):BindToRenderStep("UpdateCamera", Enum.RenderPriority.Camera.Value + 1, UpdateCamera)

I’m not sure what you mean, could you show an example?

Not sure how I can provide an example, but what I mean is when your cursor goes to the side of the screen, the camera slightly shifts towards the cursor rather than staying on the player

Could you show a video of what you’re trying to achieve?

i dont have one a video, something i envisioned more

Without a video and without any examples it’s really hard to tell what you’re trying to achieve. Could you maybe show different examples of how the camera should look depending on the cursor position?

yea i assume so, just nevermind it for now till i find proper examples

1 Like

Something like that?

you can also change the movement to match the camera.

--			Edit variables				--
local UpDistance = 25
local MaxDistance = 5

--			Service				--
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer

--			Update				--
local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
	if not Player.Character then			return		end
	--			Normal			--
	local Pivot = Player.Character:GetPivot()
	local NewCamPosition = Pivot.Position+Vector3.yAxis*UpDistance
	if UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
		--			Angle			--
		local P, O = UIS:GetMouseLocation(), Camera.ViewportSize/2
		local Angle = -math.atan2(P.Y - O.Y, P.X - O.X)
		local Distance = math.min((P-O).Magnitude/O.Y, 1)*MaxDistance

		--			Set position			--
		local CF = (Pivot.Rotation+NewCamPosition)*CFrame.Angles(0, Angle, 0)
		local Final = CF.Position-CF.LookVector*Distance
		Camera.CFrame = CFrame.lookAt(Final, Final-Vector3.yAxis)
		Camera.CFrame = CFrame.lookAt(NewCamPosition, Pivot.Position)
1 Like

oh yes this is exactly what i wanted

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