I’ve tried my best to look at tutorials, devforum posts, but all of them are using hingeconstrants and doesn’t look right. I’m looking for a swinging door that uses CFrames, and respects the boundaries of the frame, and only opens like this:
you mean you want it to open once you click on it, or like it moves when you push it with your character
Automatically open the door, no pushing the door.
This is really simple.
Just make another part (lets call it the goal) that is in the exact position where the door would be after it’s open. When the door needs to be opened, just tween the part to the CFrame of the goal.
Same thing goes for closing the door.
first you can make ur door like this. it doesn’t have to look as simple, but just make sure that it has a hinge (the grey part) on the side
then you can add a proximity prompt, and when it is clicked, run some code
I found this code on youtube but it will work. the variables would have to be change though to match the names of your model
I’ve tried this, but it will end up not respecting the door frame and due to my game being massive, it doesn’t help us limiting on part.
I’m assuming hinge is the door frame?
For testing purposes, when using that tutorial’s code, I end up something like this:
External Mediait doesn’t respect the door frame, and it seems a bit wanky.
Try this door. Does this work for you? You can make a copy if this works.
It works, I might destroy the parts after saving a variable of it. Also, it isn’t published properly and uncopylocked.
Try copying it now. Anyways, like I said before:
Simply tweening the door part to goals works. You can adjust where the goals are.
local TweenService = game:GetService("TweenService")
local f = script.Parent
local oGoal = f:WaitForChild("OpenGoal")
oGoal.Transparency = 1
local cGoal = f:WaitForChild("CloseGoal")
cGoal.Transparency = 1
local door = f:WaitForChild("DoorPart")
local cDetect = door:WaitForChild("ClickDetector")
local open = false
cDetect.MouseClick:Connect(function()
if open == true then --Close the door
open = false
TweenService:Create(door, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = cGoal.CFrame}):Play()
else --Open the door
open = true
TweenService:Create(door, TweenInfo.new(1, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {CFrame = oGoal.CFrame}):Play()
end
end)
Also, why is it opening like that? It looks wanky, is there anyway I can fix it from happening?
External MediaIf you look at the corner, the position changes and isn’t holding the frame and moving it:
External MediaAdjust the open goal to be a little less towards the edge of the door frame. It all comes down to adjusting the goals until something works.
This will do the same thing. What I’m talking about is “position changes with the angle”, and it looks wanky.
It’ll look less wanky if the goal is adjusted. Plus, if it clips slightly out of the frame it shouldn’t matter that much since the walls should hide it.
I see what you mean, but thatès the only solution I can come up with rn.
I would like to add that it makes sens that the position of the door changes since it’s not rotating on it’s own center.
I would like to add that it makes sens that the position of the door changes since it’s not rotating on it’s own center.
How would I do that to make it smooth? I don’t know how to use motor6ds, gotta get help with that, but will that work?
Sorry i dont rlly understand what you mean by ‘how would i do that to make is smooth’. could you repeat that?
Firstly, you should only do this animation with CFrames if you’re doing it from a client script (LocalScript) and the door is not collidable. Don’t animate with CFrames from a server script, or it will animate jerkily for everyone. If you want every player to see the door opening smoothly at the same time, a HingeConstraint solution is correct, CFrames and Motor6D are not.
As for how to CFrame: The simplest thing to do is to set the door part’s PivotOffset to put the pivot point on the edge of the door you want to rotate around. Then, instead of setting the door CFrame directly, you use Part:GetPivot() and Part:PivotTo(). For example, to rotate the door 45 degrees around the y-axis through the pivot point do something like
door:PivotTo( door:GetPivot() * CFrame.fromOrientation(0, 0.25*math.pi, 0))
The PivotOffset lets you move the part’s pivot point to anywhere you want, even outside the bounds of the part, rather than being limited to rotating around the center of the part bounding box. Without using the pivot, you’d have to combine multiple CFrame multiplies, to offset the door to the rotation point, then rotate it, then undo the offset. Pivot does all this for you.
I finished it, thank you for all of the help. It was a problem with my hinge, and I was supposed to weld that to the door.