Rotate part horizontally without following its orientation

lego-spin

How would i achieve the effect above where the item can be tilted and still spin horizontally

You could do something like this:

local rx, ry, rz = Part.CFrame:ToEulerAnglesYXZ()
local rotX, rotY, rotZ = 0, 0, math.rad(90) -- In radians
Part.CFrame = CFrame.fromEulerAnglesYXZ(rx+rotX, ry+rotY, rz+rotZ) + Part.CFrame.Position

If you wanted to make it rotate continuously, you could just place this inside a loop.

This is what you might’ve been using before:

while true do
local dt = task.wait()
part.CFrame = part.CFrame * CFrame.Angles(0, dt, 0)
end

This will rotate that brick around its own vertical axis like a frisbee or spinning top or such.
To get the effect in that gif, swap the order of operations:

while true do
local dt = task.wait()
part.CFrame = CFrame.Angles(0, dt, 0) * part.CFrame
end

so that the part is rotated based on the world’s vertical axis, not the part’s.

I tried this and it makes the part move and do laps in a big circle.

Their idea isn’t fully wrong, it’s just it has the wrong pivot position.

This is just the way I would do it personally:

local part = workspace.PartB

local pivot = CFrame.new(part.Position); -- // default orientation with part position
local rotation = CFrame.Angles(0, math.pi * (1/180), 0) -- // Speed
local offset = pivot:Inverse() * part.CFrame -- // the object offset from pivot

-- // Recommend a RenderStepped or Stepped function instead
-- // This is for demonstration
while task.wait() do 
	pivot *= rotation
	part.CFrame = pivot * offset 
end

But their part.CFrame = CFrame.Angles(0, dt, 0) * part.CFrame should be
part.CFrame = (CFrame.Angles(0, dt, 0) + part.Position) * part.CFrame.Rotation had to test it out and it works.

1 Like

Tried this and it works great, thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.