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:
01 | local RunService = game:GetService( "RunService" ) |
03 | local Camera = game.Workspace.CurrentCamera |
04 | local Player = game.Players.LocalPlayer |
07 | local function CalculateBounds() |
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) |
14 | local desiredPosition = Vector 3. 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) |
18 | local function FindAverageDistance() |
23 | local function Execute() |
27 | 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.