#Continuously Scale a Model?

34 messages · Page 1 of 1 (latest)

void spear
#

I'm trying to scale a large model down for 60 seconds until it reaches 20% of it's original size. How would I go about this? I tried to use a few model properties, but I'm not sure where to go next. Any help is appreciated.

gentle meteor
#

First things first, you gotta figure out the initial size of your model. Get the original size by checking out its properties in Roblox Studio. Look for the properties like 'Size' or 'Scale' and note down the initial dimensions.

Next up, let's calculate the final size we wanna reach after 60 seconds. Multiply the initial size by 0.2 (20%) to get the desired final size.

Now, let's get coding! We're gonna need a loop to gradually scale down the model over time. The simplest way to do this is by using a 'for' loop that runs for 60 seconds (or 60 frames) with a slight delay between each iteration.

Inside the loop, we'll update the size of the model each frame. Divide the difference between the initial and final size by 60, and subtract that value from the model's current size each frame. This will gradually shrink it down until it hits the target size.

Here's some example code to give you a head start:

local model = -- [Insert your model here]

local initialSize = model.Size -- Or model.Scale, depending on what you're using
local finalSize = initialSize * 0.2
local duration = 60 -- In seconds

local frames = duration * 60 -- Convert seconds to frames
local delay = 1 / 60 -- Delay between each frame (1 divided by the frame rate)

for i = 1, frames do
    local scaleFactor = (initialSize - finalSize) / frames
    model.Size = model.Size - Vector3.new(scaleFactor, scaleFactor, scaleFactor) -- Or model.Scale, again, depending on your setup
    wait(delay)
end

It should gradually shrink your model over 60 seconds until it reaches that sweet 20% of its original size. Remember to adjust the 'model' variable to match the actual model you're working with. Try it out, If it doesn't work let me know.

void spear
#

I tried calling model.Scale before, and model.Scale.Value, but the output says it isn’t a property

crimson harbor
#

Model.Scale is a property. It's tagged as "Not Scriptable", though

gentle meteor
gentle meteor
void spear
#

I’m trying to scale down the whole model over a period of time. I didn’t want to scale down each part individually because then there would be a large space between each part

#

Yeah I just put ??? because I wasn’t sure where to go from there.

gentle meteor
#

¯_(ツ)_/¯

dire swallow
#
gentle meteor
#

yeah

dire swallow
#

always look for a solution there first you'll usually find something unless its like super obscure

void spear
#

Aw man, my bad guys.

#

I was on that page before but I didn't know there was a drop down.

dire swallow
#

All good man

crimson harbor
#
local function scaleModelToPercent(model: Model, percentage: number, duration: number)
    local ORIGINAL_SCALE = model:GetScale()
    local TARGET_SCALE = ORIGINAL_SCALE * percentage
    
    if duration == 0 then
        model:ScaleTo(TARGET_SCALE)

        return
    end

    local SCALE_RANGE = TARGET_SCALE - ORIGINAL_SCALE

    local connection = nil
    local secondsElapsed = 0
    local alpha = 0

    connection = RunService.Heartbeat:Connect(function(deltaTime: number)
        if not connection.Connected then
            return
        end

        secondsElapsed += deltaTime
        alpha = math.min(1, secondsElapsed / duration)

        model:ScaleTo(ORIGINAL_SCALE + SCALE_RANGE * alpha)

        if alpha == 1 then
            connection:Disconnect()

            -- Clean up potential imprecision
            model:ScaleTo(TARGET_SCALE)
        end
    end)
end
#

That's how I would do it

#
scaleModelToPercent(model, 0.20, 1)
void spear
mossy flintBOT
#

studio** You are now Level 3! **studio

crimson harbor
void spear
#

It's not your code, it's the application of it within the game I'm making.

crimson harbor
#

How are you applying it?

void spear
#

I'm making a game where a cube rotates using roblox physics, and a person has to stay on top of the cube while it rotates.

#

Rounds are 60 seconds, and I was trying to add a round type where the cube continously gets smaller

crimson harbor
#

That shouldn't cause lag

void spear
#

Some models are also made up of 500 separate parts

#

But I'm seeing a bit of roughness on 1 part models as well

crimson harbor
#

That might be it, lol

#

Take a page from the greedy mesh algorithm

#

Try to build your model with less parts

void spear
#

alright, i'll look it into

#

Thank you so much for the code though.