How to grow an object from one side

So I want to just generally know, what would be the ideal way to resize objects, so that when it grows, it goes forward so it looks like its lengthening.

I assume it could be done with a cframe coordinate and keeping an object stuck in that place when the object is resized, but I simply don’t know how I get an objects Cframe that is not the center of mass.

Here is a simple illustration of what I want to accomplish with this:

Good question, how you accomplish this is by dynamically setting the position alongside the size increment, to do that, you divide the increment by half, and add it on the direction you wish on the position vector.

Here’s an example code:

local TweenService = game:GetService("TweenService") 

local Part = game.Workspace.Part 
local Increment = 10 

local Tween = TweenService:Create(Part, TweenInfo.new(1, Enum.EasingStyle.Quad), 
{Position = Vector3.new(Part.Position.X - Inc / 2, Part.Position.Y, Part.Position.Z), Size = Vector3.new(Part.Size.X + Inc, Part.Size.Y, Part.Size.Z)}) 
Tween:Play()

Let’s assume you want to change the X size of the part, we add the increment on the size vector by doing Part.Size.X + Inc, and to keep the position stable, we divide the Inc by half and add/remove it from the Part.Position.X vector. (Adding or removing depends on which side you’re adding the Inc from)

5 Likes

The general way to do this is to size something in the axis you want, then at the same time add half that size to the same axis, but for the position.

For example:

local Object = game.Workspace.Part

Object.Size += Vector3.new(0, 10, 0)
Object.Position += Vector3.new(0, 5, 0)

Note that you will still need to account for rotations. This sort of logic works in tweens as well!

1 Like

It works as intended.

So this code basically changes moves the part back on the X axis, by dividing Increment with 2 so 5 studs back. Then it increases the size on the X axis by adding 10 studs to the X axis.

If i’m wrong, could you explain?

Otherwise, I get it and can use this now. Thanks in advance.

Correct.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.