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

How would someone make a Smash Bros Ultimate type of camera?

Asked by
p0vd 207 Moderation Voter
4 years ago

So I've been trying to find on YT and Reddit and basically every media app and I can't seem to find help on how to make this. If you don't know what I'm talking about well basically the Smash Bro's camera takes the center of the character that is the furthest to the left and right so it adjusts the camera (zooming out) to fit those characters. Thank you!

0
Please be more specific on which part you don't get (the math, moving the camera, etc) hiimgoodpack 2009 — 4y
0
I am pretty confident on the math, the camera part no so much. p0vd 207 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

i guess setting the x and y coordinates to be the average of all the player positions, and as for the z coordinate...

-get the average of all of the player's locations, we will call this averageVector

-have a sum, called TotalMagnitude

-loop through each player...

local c = game.Players:GetChildren()
local TotalVector = Vector3.new(0,0,0)
local length = 0

for i, plr in pairs(c) do
    local char = plr.Character
    if char then
        TotalVector = TotalVector + char.PrimaryPart.Position
        length = length + 1
    end
end


local AverageVector = TotalVector/length
local TotalMagnitude
length = 0


for i, plr in pairs(c) do
    local char = plr.Character
    if char then
        TotalMagnitude = TotalMagnitude + (char.PrimaryPart.Position - AverageVector).magnitude
        length = length + 1
    end
end

local averageMagnitude = TotalMagnitude/length

--Your X value for the camera is AverageVector.X
--Your Y value is AverageVector.Y
--Your Z value is averageMagnitude (if you want it to be a little further, then Z + 5 or something, same with X and Y)

What this is doing is taking each player's distance from all of the players' average location, and finding the average distance between them all. basically, the camera will move out the further the players get from eachother. as for the x and y, thats just the average of all the players' locations. I havent tested this, so you may need to make some tweaks once you add it.

EDIT: the code above does not move the camera, it is simply the math that gets the camera position. if you would like me to make a script that does this, i would be happy to do so

0
It is your choice if you would want to. p0vd 207 — 4y
0
also, to zoom in use camera field of view. paperbagstudio 28 — 4y
0
does this script work for you, or would you like me to make one Dudeguy90539 36 — 4y
0
yes it works for me and sure you can. p0vd 207 — 4y
Ad

Answer this question