I’m trying to move a part to a position left of another part and then move it back. However, both of these parts move with the character so there are often inconsistent positions. Is the only solution to use built in attachments? Adding these attachments manually will be annoying in the long-term, so I would like to calculate it all. (Positions seem to be the most inconsistent, as the character moves a lot. The arms of the character also move up/down with camera, which affects these parts)
local offsetPos=part.Position-otherPart.Position
local offsetRot=part.Orientation-otherPart.Orientation
otherPart.Position-=part.CFrame.RightVector
otherPart.Orientation+=Vector3.new(0,0,90)
task.wait(1)
otherPart.Position=part.Position+offsetPos
otherPart.Orientation=part.Orientation+offsetRot
Yes, I have tried ToObjectSpace, attachments work great but are tiring to create (I’ll have multiple appearances of this part)
Thanks for any tips or solutions!
ToObjectSpace, like I said, I have tried but are inaccurate just like subtracting the positions. I am confused as to the root of this problem, because in theory, if the difference is a-b then a+b should give you the original position. It may have something to do with my parts and welds, as this is pretty simple math and should definitely work.
The math isn’t quite how that works as you’ve written it because Orientation is not the same as calculating in the matrices of world-space versus object space. Not my best explanation at that but you just need to know not to rely on Orientation like that, given it’s also fairly inaccurate and likes to spasm. It’s also slow.
For this problem, I would just use Roblox’s built-in CFrame math and operators within the CFrame library. It already has a Position property.
To calculate an offset position for let’s say Part1 5 to the left of Part2, you can assign its CFrame as follows: Part1.CFrame = Part2.CFrame * CFrame.new(5,0,0)
If you only want to do the position and ignore the orientation of the part you’re moving, you can do: