Removing MinZoomDistance?

I’m looking for a way to remove the clamp surrounding MinZoomDistance aswell as the part occulision when the camera is too close.

I have done this in the past by using the default PlayerModule but for the life of me I cannot replicate it.

The reason I’m doing so is I’m working on a space game, starships (Pilotable) are scaled down to 0.05 - 0.1 to give the illusion that space is much more larger.

Additionally - Would I be able to create my own Camera system to function in the desired way?

Thank you.

1 Like

Can you elaborate more? I don’t really understand what you mean by that

So basically the starships are scaled down to 0.1 of their original size (Basically miniscule) then the Player focuses on their starship currently the MinZoomDistance is clamped to 0.5 - This is still quite some distance away from the model itself.

I’m looking to remove the 0.5 clamp to allow the MinZoomDistance to be much lower.

I think it’s not possible to that since it always rounds up to .5, no matter what you do

It can be edited via the default PlayerModule scripts in StarterPlayerScripts.

I’ve done it in the past however I’m unable to replicate it for whatever reason.

are the modified script/changes in some other game? else just copy the whole script to the current game

You need to change the CameraMinZoomDistance from the player

-- example in local script
game:GetService("Players").LocalPlayer.CameraMinZoomDistance = 0

Even though, as the other guy mentioned, it is clamped to 0.5. And I don’t think the NearPlaneZ value can be edited.


Additionally, spherical coordinates could be used to build your own camera system.

Here is a more detailed version of one of my earlier postings! (to view my revision, you must slightly scroll down.)

the reference for that is here

-- Setting up the script
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local currentCamera = workspace.CurrentCamera
currentCamera.CameraType = Enum.CameraType.Scriptable

local subjectPosition = Vector3.zero -- position the camera will be looking at

local sensitivity = 0.5
local radius = 20 -- distance from subjectPosition
local theta = 0 -- x rotation in degrees
local phi = 0 -- y rotation in degrees

-- The coordinates
function SphericalCoordinate(r: number, theta: number, phi: number)
	local Position = Vector3.new(
		r * math.sin(phi) * math.cos(theta),
		r * math.cos(phi),
		r * math.sin(phi) * math.sin(theta)
	)

	local Hat_r = Vector3.new(
		math.sin(phi) * math.cos(theta),
		math.cos(phi),
		math.sin(phi) * math.sin(theta)
	)

	local Hat_theta = Vector3.new(
		-math.sin(theta),
		0,
		math.cos(theta)
	)

	local Hat_phi = Vector3.new(
		math.cos(phi) * math.cos(theta),
		-math.sin(phi),
		math.cos(phi) * math.sin(theta)
	)

	return {
		Position = Position,
		UpVector = -Hat_phi,
		LeftVector = Hat_theta,
		FrontVector = -Hat_r,
		DownVector = Hat_phi,
		RightVector = -Hat_theta,
		BackVector = Hat_r
	}
end

-- Locking the mouse
UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then return end
	if input.UserInputType ~= Enum.UserInputType.MouseButton2 then return end
	
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end)

UserInputService.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
	if gameProcessedEvent then return end
	if input.UserInputType ~= Enum.UserInputType.MouseButton2 then return end
	
	UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end)

-- Finishing up
RunService.RenderStepped:Connect(function()
	local delta = UserInputService:GetMouseDelta()
	
	theta = (theta + delta.X * sensitivity) % 360
	phi = (phi + delta.Y * sensitivity) % 360
	
	local sphericalCoordinate = SphericalCoordinate(
		radius,
		theta * math.pi / 180, 
		phi * math.pi / 180
	)
	
	currentCamera.CFrame = CFrame.fromMatrix(
		sphericalCoordinate.Position + subjectPosition, 
		sphericalCoordinate.RightVector, 
		sphericalCoordinate.UpVector, 
		sphericalCoordinate.BackVector
	)
end)

You can alter the “radius” with this camera system to be less than 0.5

I suggest reading a few articles about spherical coordinates if you’re interested in learning more about how it functions. Ask as many questions as you like. I’m not bothered.
(How to change yaw, How to add mouse controls etc)

1 Like

This has worked perfectly!
Only question I have is how can I go about clamping it to work the same as default ‘Custom’?
i.e. not allowing the camera to make a full 360 degree angle upwards?

No issue. The phi value can be clamped in the core loop.

-- Finishing up
RunService.RenderStepped:Connect(function()
	local delta = UserInputService:GetMouseDelta()
	
	theta = (theta + delta.X * sensitivity) % 360 -- Left and right
	phi = math.clamp(phi + delta.Y * sensitivity, 0, 180) -- Up and down
	
	local sphericalCoordinate = SphericalCoordinate(
		radius,
		theta * math.pi / 180, 
		phi * math.pi / 180
	)
	
	currentCamera.CFrame = CFrame.fromMatrix(
		sphericalCoordinate.Position + subjectPosition, 
		sphericalCoordinate.RightVector, 
		sphericalCoordinate.UpVector, 
		sphericalCoordinate.BackVector
	)
end)

The maximum rotation in this instance is 180 degrees, with a minimum rotation of 0 degrees.

-- Revised code
phi = math.clamp(phi + delta.Y * sensitivity, 0, 180) -- Up and down

Any other questions? If not, good luck with your development!

1 Like

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