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

Creating a Super Smash Bros Camera?

Asked by 8 years ago
Edited 8 years ago

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:

01local RunService = game:GetService("RunService")
02 
03local Camera = game.Workspace.CurrentCamera
04local Player = game.Players.LocalPlayer
05 
06 
07local function CalculateBounds()
08    local X,Y = {}, {}
09    for _,player in pairs (game.Players:GetChildren()) do
10        local position = player.Character.HumanoidRootPart.Position
11        table.insert(X, position.X)
12        table.insert(Y, position.Y)
13    end
14    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))
15    Camera.CFrame = CFrame.new(desiredPosition.X, desiredPosition.Y, desiredPosition.Z)
View all 27 lines...

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

0
You could try changing the field of view based on the distance between players. AZDev 590 — 8y
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. Objectly 49 — 8y
2
Could you post an attempt? Otherwise we're basically making the script for you. Goulstem 8144 — 8y
0
I do have some code. Let me post it Objectly 49 — 8y
View all comments (3 more)
0
Posted. Objectly 49 — 8y
0
It seems I don't even need to find the average distance. I just need to know how to handle the zoom. Objectly 49 — 8y
1
Does this still need answering? nicemike40 486 — 8y

1 answer

Log in to vote
0
Answered by
TH669 0
7 years ago

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,

01local target = workspace.Part
02local camera = workspace.CurrentCamera
03camera.CameraType = Enum.CameraType.Scriptable
04camera.CameraSubject = target
05local angle = 0
06 
07while wait() do
08    camera.CoordinateFrame = CFrame.new(target.Position)  --Start at the position of the part
09                           * CFrame.Angles(0, angle, 0) --Rotate by the angle
10                           * CFrame.new(0, 0, 5)       --Move the camera backwards 5 units
11    angle = angle + math.rad(1)
12end

This code is from the wiki.

Ad

Answer this question