I’ve tried so many things to try to rotate around it’s own pivot point or around a pivot part.
But I just became more confused about it.
So I will include a model so anybody can try it or check it: train.rbxm (10.3 KB)
There is a part called “Power” which is connected to the wagon by weld, on top of that is a pivot part connected by motor6d to the pole part (I’ve tried without physical parts too) and the pivot part connected by weld to the lever.
I’ve already tried make it the whole thing a model, setting a primary cframe, lots of different formula and calculate into Orientation.
If I am not mistaken the official doc says something about you can’t move parts by CFrame when they are connected or atleast if you want to move a part locally (without affecting the other connected parts). So I converted everything to Orientation:
local rx, ry, rz = newFrame:ToOrientation();
local dx, dy, dz = math.deg(rx), math.deg(ry), math.deg(rz);
lever.Orientation = Vector3.new(dx, dy, dz);
However the best result was only rotation in a very weird angle (spin around on local X axis or around it’s center).
So to summerize: I want to achieve the level part to rotate around it’s pivot point in right or left direction.
local pivot = Vector3.new(0, 0, 0)
local part = workspace.Part
local newpivot = CFrame.new(pivot) -- Create decoy pivot that will "rotate"
local offset = newpivot:toObjectSpace(part.CFrame) -- Get the offset from the part to the pivot
while wait() do
newpivot = newpivot * CFrame.Angles(0, math.rad(1), 0) -- Rotate the pivot
part.CFrame = newpivot * offset -- Re-offset the part from the new rotation
end
I’ve seen this answer in some other topics and I don’t in the past I’ve tried this too.
The wagon just starts flying randomly, it looks very glitchy and other parts move with the wagon.
With this modification, the lever rotates locally but around it’s own center not around the pivot point.
local pivot = Vector3.new(0, 0, 0)
local part = script.Parent
local newpivot = CFrame.new(pivot) -- Create decoy pivot that will "rotate"
local offset = newpivot:toObjectSpace(part.CFrame) -- Get the offset from the part to the pivot
while wait() do
newpivot = newpivot * CFrame.Angles(0, math.rad(1), 0) -- Rotate the pivot
local newFrame = newpivot * offset -- Re-offset the part from the new rotation
local rx, ry, rz = newFrame:ToOrientation();
local dx, dy, dz = math.deg(rx), math.deg(ry), math.deg(rz);
part.Orientation = Vector3.new(dx, dy, dz);
end
I am starting to think the problem here is the conversion to Orientation not the CFrames