Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I constantly zoom in and out with the camera?

Asked by 7 years ago

Hold your horses!

The question may seem simple - but as it's 11:30 where I'm at and I got a brainfart, I just need some help. See, I am using WorldToViewportPoint and the camera's interpolate method - but...

...I do not know how to go about getting the players inside the game and constantly changing the camera with a loop/event to get it show all players while not making the camera FoV excessively large.

Kind of like Brawlhalla's camera where it constantly expands and decreases its range to fit all players within the screen. It zooms in when they're all bundled and zooms out when they're not.

Yeah, I'm using BindToRenderStep if you were wondering as well. Pretty neat feature.

Anyways, thanks for helping.

Here's the code:

local Unity = require(game.ReplicatedStorage:WaitForChild("Unity.Api"))() --Ignore
local Project_Arkadata = Unity:InitializeApplication("ArKaDatTa") --Ignore

--// Initialization

local RunService = game:GetService("RunService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Camera = game.Workspace.CurrentCamera

local offset = 2 --Me thinking of ways to manipulate camera to zoom in and out

Camera.Focus        = Player.Character.HumanoidRootPart.CFrame

local function onRenderStepped()
    local target        = game.Workspace.Part
    Camera.Focus        = Player.Character.HumanoidRootPart.CFrame
    Camera.CameraType   = Enum.CameraType.Scriptable
    if Character then
        local rootPart  = Character.HumanoidRootPart
        Camera.CFrame   = CFrame.new(target.Position + rootPart.Position) * CFrame.new(-18, 2, (Player:DistanceFromCharacter(target.Position))*offset)
    end
end

local function onCharacterAdded(character) --Just lazy to use online mode, solo mode less lag
    Character = character
end

local function ManageView() --Me thinking of ways to manipulate camera in and out
    for _,player in pairs (game.Players:GetChildren()) do
        local bool = Camera:WorldToViewportPoint(player.Character:WaitForChild("HumanoidRootPart").Position)
        if not bool then --This conditional won't do enough by itself...Hmmm
            offset = offset + 1 
        end
    end
end


if not game:GetRemoteBuildMode() then
    onCharacterAdded(Character)
end


Player.CharacterAdded:connect(onCharacterAdded)
0
tl;dr - More so looking for an efficient idea/method/algorithm to go about with this. AbstractCode 16 — 7y
0
Get the distance between the two farthest players and try to fit those two on the screen? Overscores 381 — 7y
0
Yeah, I was thinking about something like that. Using a loop to find the players with the largest distances or make it relative to the distance of the farthest player. Just wanted to see if there were any more efficient methods. AbstractCode 16 — 7y

Answer this question