I created a door that uses ProximityPrompts and swings open. It uses TweenService to swing open/close the door. However, the door clips through the doorframe while tweening, causing it to look horrendous:
How could I fix this issue? I can provide scripts I’m using and door objects in Explorer. I have also looked at using hinges, but I simply could not figure it out for whatever reason.
You’re going to have to rotate your door around a pivot.
You can do complex math to figure this out with custom tween functions or…
Just use Motor6D’s, set the appropriate Part0 and Part1 then use the CFrame (or Desired/CurrentAngle) properties of the Motor6D to rotate your door. You can tween these values as well.
NOTE: Part0 of your Motor6D has to be anchored, Part1 of your motor has to be unanchored, and your entire door must be welded to your Part1 and also unanchored.
I absolutely think using a weld in the way you’re describing is so much simpler, and that’s what came to my mind first as well. However, I also tried implementing the pivot system and it wasn’t as complicated as I thought, and it might be more performant if all parts are anchored and neither the server/client have to care about running loose-y physics for every door in the game. I may just have a phobia of clients having physics ownership over unanchored parts.
First, the pivot should be set to the hinge face of the door. The door needs to contain a NumberValue Instance (named SwingAngle) that TweenService can target and manipulate, and a RunService event needs to read the ValueObject and run some light math to calculate a CFrame that’s provided to a :PivotTo() call.
This is what I’d imagine is called every time the RunService event fires and if the door should be moving during this moment:
-- doorDefaultPivot is a predefined variable set to door:GetPivot() when the door is closed
-- SwingAngle is the NumberValue Instance we're tweening
door:PivotTo(doorDefaultPivot * CFrame.Angles(0, math.rad(SwingAngle.Value), 0))
If the SwingValue is 0, the door angle is 0, and it’s closed. If it’s 90, it’s open 90 degrees. A Tween targeting SwingValue can tween its heart out, and RunService will repeatedly update the door (and all its parts) to the appropriate position.
I honestly wish this solution didn’t have to use a ValueObject, but since Fizzy is tweening the door, it can’t directly tween using a pivot.
Under the model tab in Roblox Studio, there’s a Pivot section. Activate the Edit Pivot option while you have your door selected, and it’ll introduce a movable and rotatable handle that should snap to faces/edges/corners. Once it’s set the way you want it, just click Edit Pivot again so you don’t accidentally move it because it looks very similar to the generic move/rotate handles.