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

How to elongate a part while maintaining alignment?

Asked by
Ribasu 127
5 years ago
Edited 5 years ago

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.

0
Get and store the current position. Resize. Set the position to the stored position. Profit?! ScrewDeath 153 — 5y
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? Ribasu 127 — 5y
0
Your part gets elongated by 10 on the X, now elongate the Z axis by 5. User#19524 175 — 5y
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. ScrewDeath 153 — 5y
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. ScrewDeath 153 — 5y

1 answer

Log in to vote
0
Answered by
OBenjOne 190
5 years ago

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

Ad

Answer this question