Rotation around a position in "3D"

Hello, I recently faced such a task.
I need to make the rotation of the parts around the center in “3D”, that is, so that each part has its own axis, and it turns around it without colliding with the positions of other parts.
An example of how I created “2D” rotations is in the screenshot
(c = counter, Center = Central position)

I tried experimenting, searching for information on the Internet, but I didn’t understand it that way.

(Sorry, I don’t know English well and most of the text is written through a translator).

1 Like

I’m not the best with math, but I would usually use CFrames to get my way out of tasks like this.

If you created a CFrame using CFrame.Angles, you could plug in radian values to easily change the direction the CFrame faces. From there, you can take the LookVector of the CFrame and apply that as the position.

I would set a random X and Z value to create the unique axis and then lerp the Y value so the CFrame rotates around its axis, constantly getting the LookVector and plugging it into the part position.

local point = CFrame.new(0,0,0)
local part = -- part you want to rotate
local offset = CFrame.new(0,0,10) -- offset for the part
local inc = 1 -- how much to rotate
while task.wait() do
     part.CFrame = point*CFrame.angles(0,math.rad(inc),0)*offset
end

In the code itself, I use CFrame, just my problem is the positioning of objects.

Yeah and you can still use it fine, I just mean you can use the orientation part of a CFrame to create the axis and then get the LookVector of the frame to give you an offset position. From there you can use your existing CFrame. @Qinrir shows it off fairly well.

Instead of getting an extremely accurate version of a vector3 value with trigonometry, you can just orient the part so it’s on the axis you want it to rotate around. Then all you would need to do is get the look vector of the CFrame. You can also multiply it by a vector offset, but for me, LookVectors are more straightforward.

To rotate it you can change the axis currently it’s in the XZ Axis form the code.

local pos = center + Vector3.new(x,0,z)

Please paste your code instead of screenshotting next time.

To change the XZ axis and rotate it use CFrame multiplication

local pos = center + CFrame.Angles(0,0,math.pi/4)*Vector3.new(x,0,z)

This will rotate the XYZ axis by 45 degrees along the Z axis. This should be different for each part to create an atom effect.

2 Likes