So I am trying to make a saw which rotates forward every update.
The solution would be a lot easier if I could use simple CFrame methods, because I know those are working. Sadly, this is not an option because I use Welds on my vehicles (probably I could change them to Motor6D, but that would require more time now).
So this is the script currently:
local saws = {};
for _, child in script.Parent:GetChildren() do
if child.Name == "Saw" then
table.insert(saws, child);
end
end
RunService.Heartbeat:Connect(function(delta)
for _, saw : Part in pairs(saws) do
local rotation = saw.CFrame * CFrame.fromEulerAnglesXYZ(0,0,0.1);
local x, y, z = rotation:ToEulerAnglesXYZ();
saw.Orientation = Vector3.new(math.deg(x), math.deg(y), math.deg(z));
end
end)
The problem is the saws seems like they lose their initial direction (probably because I don’t use CFrame) and after that they rotate around the Y axis. I don’t want to limit it to only work when the saw is placed horizontally or directionally and I can’t really find any solution for this.
I’ve also attached the whole as a model to make it easier to test: test.rbxm (5.5 KB)
Okay, so I’ve tried to change to Motor6D as the join type between the two object.
RunService.Heartbeat:Connect(function(delta)
for _, saw : Part in pairs(saws) do
saw.CFrame = saw.CFrame * CFrame.fromEulerAnglesXYZ(0,0,-0.1);
end
end)
But overall this makes all parts to teleport in one place
Sadly TweenService doesn’t mean a lot difference (because I still need to use CFrame, which it still effects the other connected parts)
I’ve tried use WeldConstraint, Weld and Motor6D, however because I use a building system I’d like to keep the WeldConstraint’s logic which makes all part keep position relative from eachother. With Moto6D and Weld if you manually move any of the objects the connection will break apart. Or atleast it did for me.
I’ve tried using AngularVelocity too, without success. As long as I use any physical joint I can’t use CFrame or Velocities in any way.
I still don’t understand why Roblox makes the physics engine this complicated to use.
If you want to do this via the Orientation property, you can try using :ToOrientation() instead of :ToEulerAnglesXYZ()
RunService.Heartbeat:Connect(function(delta)
for _, saw : Part in pairs(saws) do
local rotation = saw.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, delta*6);
local x, y, z = rotation:ToOrientation();
saw.Orientation = Vector3.new(math.deg(x), math.deg(y), math.deg(z));
end
end)