Hello, I want to tween (rotate) a motor6d on a pivot as the title suggests.
I am making an unanchored door which the player will be able to weld onto moving vehicles and other unanchored parts so I can’t tween the door hinge itself, and have to use a motor6d to do so.
I have tried some solutions such as fiddling with the cframe, tweening C1 and C0, I have a basic understanding of CFrame but I just don’t know how to get this to work.
doorHandle.ClickDetector.MouseClick:Connect(function()
-- if debounce is false, do the things below, if it is true, wait until it becomes false
if doorDebounce == false then
-- if the door is open, set doorOpen to true, if its closed, set doorOpen to false
if doorOpen == false then
doorOpen = true
doorDebounce = true
tweenService:Create(motor6d,tweenInfo,{C0 = motor6d.C0 * CFrame.Angles(0,math.rad(90),0)}):Play()
mainDoorPart.door_open:Play()
task.wait(delay)
doorDebounce = false
else
doorOpen = false
doorDebounce = true
tweenService:Create(motor6d,tweenInfo,{C0 = motor6d.C0 * CFrame.Angles(0,math.rad(-90),0)}):Play()
mainDoorPart.door_close:Play()
task.wait(delay)
doorDebounce = false
end
end
end)
Here is what ends up happening after I run the script
It just rotates really weirdly, and I think that is because I have an offset cframe on the motor6d.
Here are the properties of the Motor6D, I have also read about rotating offset parts on a pivot but none of the results talk about Motor6D or a method that could work with Motor6D and unanchored parts.
You can make a HingeContraint (with the door’s attachment set to the same place where a door normally would have hinges), and then set its ActuatorType to Servo. After that, you can just simply edit the TargetAngle of the hinge. Just make sure that AngularSpeed is not set to 0.
As @fofogoofan12 said just use a HingeConstraint. I’ve used them set to Servo for my vehicle doors for years.
The other way is to use a Motor and not a Motor6D. Then you can just set the DesiredAngle (like setting the TargetAngle of a HingeConstraint) to whatever angle you want.
Sorry but I need the door to be unanchored so the player will be able to weld it to their moving vehicles, and you cant tween unanchored parts, this is why I used motor6ds, because you can tween the C0 and C1 values even when the model is unanchored.
Sure, its kinda late for me right now so I will try that tomorrow
Also make sure your HingeConstraint Servo max force is not set to something huge so if the door gets caught on a lamppost or a player it won’t get the vehicle stuck.
You can also play with the Restitution, which will give a bit of a more natural movement instead of a linear closed to open movement.
Check out how it looks at my Suspension Test place on my profile.
Yep its probably due to this reason. If you want to visualize a Motor6D and edit this pivot position I recommend using a plugin like RigEdit or the roblox Constraints visualization which I believe displays Motor6ds as well.
Wow this worked perfectly, I used rigedit and it immediately worked, thanks so much!
Edit: @dthecoolest but now I just realized that I can somehow phase through the door now, even when its cancollide is set to true, do you know how to fix this?
Edit 2: it seems like changing a property of the door parts after it has completed its move with the motor6d fixes it, here is a local function I used to do this
-- fixes collision after motor6d tween
local function fixCollision()
for _,v in pairs(door:GetChildren()) do
if v:IsA('BasePart') then
v.Massless = true
task.wait()
v.Massless = false
end
end
end