I made a 3d gui however when i change the players fov it disappears because the camera zooms in, i don’t think showing my code is really necessary for this but ill show it anyway:
Video
Code
--SERVICES--
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local workspace = game:GetService("Workspace")
--PLAYER--
local camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Root = Player.Character:WaitForChild("HumanoidRootPart")
--CAMERA--
local vs = camera.ViewportSize
--GUI--
local Frame = ReplicatedStorage.GUI.MainGUI:Clone()
Frame.Parent = workspace.CurrentCamera
local Main = Frame.Main
local INVSGUI = Frame.Inventory.SurfaceGui
INVSGUI.Parent = Player.PlayerGui
local MAPSGUI = Frame.Map.SurfaceGui
MAPSGUI.Parent = Player.PlayerGui
--UserInputService.MouseIconEnabled = false
local xRatio = camera.ViewportSize.X/camera.ViewportSize.Y
local yRatio = camera.ViewportSize.Y/camera.ViewportSize.X
Frame.Inventory.Position = Frame.Inventory.Position + Vector3.new(-xRatio * 2.2, yRatio, 0)
Frame.Map.Position = Frame.Map.Position + Vector3.new(xRatio * 2.65, yRatio, 0)
local offset = Vector3.new(
0, --horizontal scale
-0.25, --how far down or up it is
0.5 --depth
)
local CalculatedOffset = CFrame.new(
offset.X * xRatio,
offset.Y * yRatio,
-offset.Z
)
local rotOffset = Vector3.new(0, 0, 0)
local calculatedRot = CFrame.Angles(math.rad(rotOffset.X), math.rad(rotOffset.Y), math.rad(rotOffset.Z))
local Turn = 0
local Lerp = function(a, b, t)
return a + (b - a) * math.clamp(t, 0, 1)
end;
local angleX, x, y, tilt, vX, vY, sX, sY = 0, 0, 0, 0, 0, 0, 10, 10
local TouchEnabled = UserInputService.TouchEnabled
--* UserInputService.MouseIconEnabled = flase
local randomX, randomY = nil, nil
local function lerp(v1, v2, t)
return v1 + (v2 - v1) * t
end --rewrite.by:2112Jay
local lastCF = camera.CFrame
local sway = CFrame.new()
local sinValue = 0
local lerpVal = 0
local cameraCFrame = CFrame.new(0,0,0)
RunService.RenderStepped:Connect(function(dt)
local deltaRatio = 60 / (1 / dt) --//deltaFramerate is the framerate you want things to update in, 60 is usually a good pick
local function calculateSine(speed) --//for idle sway
sinValue += speed * deltaRatio
if sinValue > (math.pi * 2) then sinValue = 0 end
local sineY = 0.01 * math.sin(2 * sinValue)
local sineZ = 0.01 * math.sin(sinValue)
local sineCFrame = CFrame.new(sineZ, sineY, 0)
return sineCFrame
end
local swaymultiplier = .25 --//sway speed
local x, y, z = workspace.Camera.CFrame:toObjectSpace(lastCF):ToOrientation()
sway = sway:Lerp(CFrame.Angles(math.sin(x) * swaymultiplier,math.sin(y) * swaymultiplier, 0), 0.15) --//for gun sway
local sineCFrame = calculateSine(0.04)
pcall(function()
local nswayPos = (camera.CFrame * cameraCFrame * sineCFrame) * sway
Frame:SetPrimaryPartCFrame(nswayPos)
end)
lastCF = camera.CFrame
if Player.Character:FindFirstChildOfClass("Tool") and Player.Character:FindFirstChildOfClass("Tool"):HasTag("Gun") and Player.Character:FindFirstChildOfClass("Tool"):GetAttribute("Aiming",true) then
end
end)
RunService:BindToRenderStep("CameraSway", Enum.RenderPriority.Camera.Value + 1, function(deltaTime)
local MouseDelta = UserInputService:GetMouseDelta()
Turn = Lerp(Turn, math.clamp(MouseDelta.X, -6, 6), (1 * deltaTime))
camera.CFrame = camera.CFrame * CFrame.Angles(0, 0, math.rad(Turn))
end)
any help is appreciated