How can I fix this door Tweening issue?

Hello fellow developers,

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.

Thanks,
Fizzitix

1 Like

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.

1 Like

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.

2 Likes

@OKevinO and @wiremass I am on my phone right now but I will definitely try these later!

Thanks,
Fizzitix

Could this also be done using an Attribute, since I’m trying to use those instead of Values?

Nevermind, just did a quick lookup, you can’t tween Attributes. Maybe this is a possible future feature?

It works, however, it doesn’t rotate on the hinge, which I’m sure this is for:

Sorry if this seems stupid (not very experienced with pivots), but how could I achieve this?

Thanks,
Fizzitix

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.