Long ago, I was trying to figure out how to calculate the DepthScale. How to calculate DepthScale? For setting avatar properties not through the avatar editor on the website
Today, I finally found the formula, and that’s the only thing I will be sharing, not the source. This formula is going to be useful any Avatar Editing Component, e.g. for @ItsMuneeeb to apply it in a game like Catalog Avatar Creator - Roblox, as Depth is auto-calculated.
Why do I need a DepthScale Formula?
You don’t…
But by default, the Roblox Avatar Editor, does not allow you to modify the depth
manually, it is calculated automatically in the backend by Roblox itself. If you want accurate previews or re-scaling adjustments, YOU WILL NEED this accurate formula.
DepthScale Formula
Depth is calculated based on the width.
A decrease Ratio is defined. This decrease Ratio takes the value from ScaleDepthWidthRatio
which is set to 0.5
.
This is used to calculate that what I will define as preDepth
.
At the end, to get the actual depth
, you’ll have to clamp it from it’s Min and Max from the https://avatar.roblox.com/v1/avatar-rules (but it’s not there, so you won’t need to min. max it)
At the end the formula looks like so: (note this is NOT code)
- The
0.5
is theScaleDepthWidthRatio
used as the decrease Ratio. - The
increment
is used for decimal conversions for roundings and other stuff, it’s pretty smart actually. -
ROUND_HALF_TO_EVEN
, seeMath.Round
from C# (Regular Lua Round won’t work)
increment = 0.01
preDepth = 1 - (1 - width) * (0.5)
depth = increment * ROUND_HALF_TO_EVEN( preDepth / increment )
And there you go!
I tried to do a desmos for this as well: Desmos | Graphing Calculator
Again, the end result depends on Round Half To Even, there are various of functions, the one on desmos is probably not the best.
Additionally
I am very happy to have finally discovered this, as I was seeking it once, and I am glad to share it.
If you were looking, or are using this for something specific, feel free to reply what you’re using this formula for, down below.
Feel free to ask any questions.