Repositionpart relative to orientation

I know this is a dumb question (Don’t judge) but literally cannot think today.

So here it is:

How does one resize + Reposition a part relative to orientation

current code

Code designed to resize a cylinder ‘upwards’

HitPart.Size = HitPart.Size + Vector3.new(0.01, 0, 0) 
HitPart.Position = HitPart.Position + Vector3.new(0, 0.005, 0) 

Im 99% confident there is just some places I should shove CFrame in, but as I said can’t think rn :frowning:

May you explain how this helps me actually solve my issue?

No, relative to the orientation of the part im resizing.

To offset a part’s position in object space you should use CFrame:ToWorldSpace.

local x = 0.01
HitPart.Size = HitPart.Size + Vector3.new(x, 0, 0) 
HitPart.CFrame = HitPart.CFrame:ToWorldSpace(CFrame.new(0, x/2, 0))
1 Like

Seems to be working relative to orientation, however now the position doesn’t seem to be rising properly / at all rising normal instead of just straight ‘upward’ like intened behaviour?

I’m not exactly sure what you’re asking for. If you want the part to go up on the Y axis regardless of the part’s orientation then the code you posted should work fine.

Instead of

HitPart.Position = HitPart.Position + Vector3.new(0, 0.005, 0)

It would be

HitPart.Position = HitPart.Position + HitPart.CFrame.RightVector * 0.005

If you’re looking to move a cylinder in the axis perpendicular to the base, that is.

The easiest way to do this is to use CFrame instead of Position

HitPart.Size = HitPart.Size + Vector3.new(0.01, 0, 0) 
HitPart.CFrame= HitPart.CFrame* CFrame.new(0.005,0, 0) 

https://gyazo.com/13020be4f159f112dd3814b9c1eb7410 Expected result

Result when pot is tilted.

Tried all solutions so far, none seem to have worked.

The easiest method is to just multiply with a CFrame.
Doing so applies the transformation relative to the given CFrame.

HitPart.CFrame = HitPart.CFrame * CFrame.new(relativeX, relativeY, relativeZ)
The long axis of cylinders is the X axis, so you’d probably want to transform along X and have Y and Z be 0 :slightly_smiling_face:

PS @dispeller you cannot sum up CFrames.

https://gyazo.com/589061b4b7eb017a7c4a91f0f0a1c285 Now the liquid seems to be seeping through the bottom, tried inverting the X to see what happened and it also gave an unexpected result.

wops, my mistake
yea, multiply not add

didn’t ping me because the reply was to someone else

That’s some other mistake on your end, it appears to be moving along the right axis now.

Probably want to position the inner cylinder relatively to the outer cylinder rather than relatively to itself.

The inner cylinder is welded with a weld constraint to the outer cylinder so the position should be relative by automatic?

Now that you mentioned it, using welds (not WeldConstraints) is probably a lot better in the first place.

For a given weld, weld.Part1.CFrame = weld.Part0.CFrame * weld.C0 * weld.C1:Inverse() holds.
All you’d have to do is set C0 to a CFrame with some X value and 0 for Y and Z.

WeldConstraints do not define a relative position, they only cause the physics solver to physically connect the parts. Manually changing the CFrame of either part causes the constraint to be updated.

Found a rather annoying but plausible solution:

Part.CFrame = Part.CFrame * CFrame.new(-0.005, 0, 0) works, however only if the part and al parts welded to It are anchored which kinda sucks.


Why on earth does the position then revert to what it was before if you unanchored it…

If you want to prevent things going through things, consider using GetTouchingParts, region3, or raycasts

No, basically the frame solution works so long as the part is anchored, however the second you unanchor it, it reverts to its original CFrame.

1 Like

So have a primary part and save the cframe in relation to the primary part and then reapply the saved cframe.

Screen Shot 2020-06-17 at 18.27.03

Parts don’t have primary parts.