I’m just making a game and I did this custom camera module (I want to notice that is my first time doing it).
local cameraM = {}
local canZoom = true
local angle = 0
local camYPos = 50
local distance = 55
local char
local hum
function cameraM:start()
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local camera = workspace.CurrentCamera
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
uis.MouseIconEnabled = false
camera.FieldOfView = 30
camera.CameraType = Enum.CameraType.Scriptable
cameraM:step()
local function body(char)
for _,part in ipairs(char:GetDescendants()) do
if part:IsA("BasePart") then
part.LocalTransparencyModifier = 0
end
end
end
player.CharacterAdded:Connect(body)
uis.InputChanged:Connect(function(input,chatting)
if chatting then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
if input.Delta.X < 0 then
angle -= 2
elseif input.Delta.X > 0 then
angle += 2
end
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
if canZoom == true then
if input.Position.Z > 0 then
if camYPos > 10 then
camYPos -= 5
end
if distance < 55 then
distance += 5
end
elseif input.Position.Z < 0 then
if camYPos < 50 then
camYPos += 5
end
if distance > 35 then
distance -= 5
end
end
end
end
end)
end
function cameraM:step()
local players = game:GetService("Players")
local player = players.LocalPlayer
local camera = workspace.CurrentCamera
local runS = game:GetService("RunService")
runS.RenderStepped:Connect(function()
char = player.Character or player.CharacterAdded:Wait()
hum = char:FindFirstChild("Humanoid")
if char and hum then
local x = distance*math.cos(math.rad(angle))
local z = distance*math.sin(math.rad(angle))
local cameraP = Vector3.new(x,camYPos,z)
local hrpP = char.HumanoidRootPart.Position
cameraP+=hrpP
camera.CFrame=CFrame.new(cameraP,hrpP)
end
end)
end
function cameraM:body(char)
end
return cameraM
It works but even that I changed the Mouse Behavior to LockCenter I still need to press right click to rotate the camera, and when I “zoom” in to the max the character hides and looks to the camera like if I were in first person.
https://gyazo.com/6b72b43f12baf764767e9b59ad7f82b5