Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Creating a Super Smash Bros Camera?

So I've been thinking about how to replicate this into ROBLOX.

Let's grab all the players and find the centered position by finding the mean value of their Vector3 positions.

We will also grab the bounds by looping to find which players are the farthest in terms of x and y. Our z will be our "zoom" axis as that's what we'll use to zoom in and out.

Now:

We have our bounds and desired position/centre of the camera. The issue now comes how do we code this?

SSB has the camera zoom in and out based on the distances of characters relative to each other. I believe this is due to their focus box decreasing and expanding in size. ROBLOX's API is quite different from Unity's so I was wondering if anybody may help guide me into a proper route into manipulate the camera.

In addition, the Camera:Interpolate function seems broken as I can't seem to cast an instance of CFrame but using CFrame.new by itself is fine and the value exists.

My code thus far:


local RunService = game:GetService("RunService")

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer


local function CalculateBounds()
	local X,Y = {}, {}
	for _,player in pairs (game.Players:GetChildren()) do
		local position = player.Character.HumanoidRootPart.Position
		table.insert(X, position.X)
		table.insert(Y, position.Y)
	end
	local desiredPosition = Vector3.new((math.min(unpack(X)) + math.max(unpack(X)))/2, (math.min(unpack(Y))+ math.max(unpack(Y)))/2, (math.min(unpack(Y))-math.max(unpack(X), unpack(Y)))/2*math.tan(90-Camera.FieldOfView/2))
	Camera.CFrame = CFrame.new(desiredPosition.X, desiredPosition.Y, desiredPosition.Z)
end

local function FindAverageDistance()
	
end


local function Execute()
	CalculateBounds()
end

RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, Execute)

Now this is a bit empty as I want to get the bounds formula correct. I've been trying multiple was and still am.

7 comments

0

You could try changing the field of view based on the distance between players.

0

The problem with that is gives up a lot of the camera control I have. E.G. I don't want the camera to follow players who go out of a specific radius.

2

Could you post an attempt? Otherwise we're basically making the script for you.

0

I do have some code. Let me post it

0

Posted.

0

It seems I don't even need to find the average distance. I just need to know how to handle the zoom.

1

Does this still need answering?

1 answer

Hey Objectly,

I don't completely understand this topic, though I do have some code that may help. This topic is called Camera Manipulation. You can find more information here: Wiki

Here is some code that may help,

local target = workspace.Part
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 0
 
while wait() do
    camera.CoordinateFrame = CFrame.new(target.Position)  --Start at the position of the part
                           * CFrame.Angles(0, angle, 0) --Rotate by the angle
                           * CFrame.new(0, 0, 5)       --Move the camera backwards 5 units
    angle = angle + math.rad(1)
end

This code is from the wiki.

This discussion is preserved as it was. New answers, comments, and votes are closed.