Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to elongate a part while maintaining alignment?

Dear scripters, as we know from the basics, we can change a part's size by changing the size property. Let's say I have

part.Size = Vector3.new(10,2,5)

then,

part.Size = Vector3.new(20,2,5)

will elongate my part by 10 units on the X dimension.

The problem with this approach is that the part's position will also change and will be out of alignment with the old one. How can one change the size, for example elongating/stretching a brick, while maintaining alignment?

Here is a pic in order to make my point clearer visually: https://imgur.com/a/SaRS7Ty

Of course, I am here as I am looking for a programmatic solution; this is an easy task using the studio interface.

5 comments

0

Get and store the current position. Resize. Set the position to the stored position. Profit?!

0

That's what I don't want. With reference to the attached picture, it will center the parts rather than align them... unless I have misunderstood your comment?

0

Your part gets elongated by 10 on the X, now elongate the Z axis by 5.

0

Oh, my bad, haha. I misread your question. I guess you can try adding half the difference between the sizes. If you grow the part by Vector3.new(5,0,0), you'll displace it by Vector3.new(2.5,0,0). I THINK that should work fine.

0

This would only apply to growth on the positive direction of the axes. You'd have to displace with negative vectors if the growth is towards the negative direction.

1 answer

This could get a bit complicated. I'm not the best programmer and have not tested this but you could try:

Xgrow = 10
Ygrow = 0
 Zgrow = 0
part = workspace.Part
--saves Position 
PartPositionX = part.Position.X
PartPositionY = part.Position.Y
PartPositionZ = part.Position.Z

--saves size
PartSizeX = part.Size.X
PartSizeY = part.Size.Y
PartSizeZ = part.Size.Z

part.Size = Vector3.new(PartSizeX + Xgrow,PartSizeY + Ygrow,PartSizeZ + Zgrow)
RepositionX = Xgrow / 2
RepositionY = Ygrow / 2
RepositionZ = Zgrow / 2
part.Position = Vector3.New(PartPositionX + RepositionX, PartPositionY + RepositionY, PartPositionZ + RepositionZ)

This will let you grow parts by changing Xgrow, Ygrow, and Zgrow. Kind of like studio. Tell me if this doesn't work right. As I said I didn't test it

This discussion is preserved as it was. New answers, comments, and votes are closed.