How to make a top-down camera view with the ability to zoom in and out

I want to make a top-down camera view but you can zoom in and out (like this)
robloxapp-20240411-1326134.wmv (1.1 MB)
But the camera is actually top-down.

(if you came from the following post, you can click on following post to go back)

This is quite easy. Here, let me break it down for you;

  • First, we assign basic variables like the player’s character and it’s HumanoidRootPart and of course the camera instance.
  • Second, we use RunService loop to constantly update the camera every single frame.
  • Third, we use some simple CFraming, like so;
local cameraDistance = 100 -- The distance of the camera from the HumanoidRootPart.
Camera.CFrame =*distance)*CFrame.Angles(math.pi,0,0) -- I am not using CFrame.lookAt as it can cause some jittering due to some delay.
  • Forth, for distance calculations we can use UserInputService. (Learn more about UserInputService here → ) We can use UIS to get our scrollwheel’s delta and accordingly add or subtract the distance. Something like this;
UserInputService.InputChanged:Connect(function(Input,gameProcessedEvent) -- Make sure to use InputChanged rather than InputBegan as InputChanged detects all changes including Began and Ended!
	if not gameProcessedEvent then -- We see if the player is not scrolling on a ScrollingFrame.
		if Input.UserInputType == Enum.UserInputType.MouseWheel then
			cameraDistance = math.clamp(cameraDistance - Input.Position.Z,0,100) -- Input.Position.X and Y and the mouse's position in pixels.

I hope this helped you! Have a good day!~ <3

The camera is not pointing down

Can I see your code? My purpose was to simply give you an idea on how it should work.

Nevermind I got it to point down

I think it should be CFrame.Angles(), not

Oh, whoops. Sorry for that! I wrote it in the devforum so it seems that I didn’t see it! Sorry for that!

Great! I am glad that I helped you achieve your goal!

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