Hey guys! Today , I will be teaching you how I made my door model
It is a drag and drop door which is easy to use regardless of what your door design is!
How it is made:
DISCLAMER THIS IS AN OVERSIMPLIFIED EXPLANATION ALL THE SCRIPT TYPED IN THE EXPLANATION WILL NOT WORK IF YOU JOIN THEM TOGETHERE
SCROLL ALL THE WAY DOWN TO STEAL THE FREE MODEL LOL
So to open the door , we will be using PropximityPrompt
local DoorOpen = false
ProximityPrompt.Triggered:Connect(function(plr)
--fires when proximity prompt activated by a player
end)
now lets say the door is close and we fire the proximity prompt . This action should cause the door to open . Thus , we will use this if statement
if DoorOpen == false then
DoorOpen = true
else
DoorOpen = false
end
your script now should look like this
local DoorOpen = false
ProximityPrompt.Triggered:Connect(function(plr)
--fires when proximity prompt activated by a player
if DoorOpen == false then
DoorOpen = true
Open()
else
DoorOpen = false
Close()
end
end)
Now since the door model I made use a CFrame hinge system, we will be using tweening to rotate the hinge. You might be wondering how the door open when the hinge rotate … well … I welded the door to the hinge and made the door unanchored .
Problem: Well… we cannot really Tween an anchored object … can we???
Solution: We can create a CFrameValue and tween the CFrame value instead . We then write an event which fires when the CFrameValue’s CFrame change
script:
local TS = game:GetService("TweenService")
local CFrameValue = Instance.new("CFrameValue",hinge)
local OpenGoal = {}
OpenGold.Value = HingeCloseCF*CFrame.Angle(0,math.rad(openAngle),0)
local OpenTween = TS:Create(CFrameValue,TweenInfo.new(doorOpenTime),OpenGoal)
local CloseGoal = {}
CloseGoal .Value = HingeCloseCF
local CloseTween = TS:Create(CFrameValue,TweenInfo.new(doorOpenTime),OpenGoal)
That script basically Handle the CFraming of the door . So in theory , the script should look like this
local DoorOpen = false
ProximityPrompt.Triggered:Connect(function(plr)
--fires when proximity prompt activated by a player
if DoorOpen == false then
DoorOpen = true
Open()
else
DoorOpen = false
Close()
end
end)
function Open()
local OpenGoal = {}
OpenGold.Value = HingeCloseCF*CFrame.Angle(0,math.rad(openAngle),0)
local OpenTween = TS:Create(CFrameValue,TweenInfo.new(doorOpenTime),OpenGoal)
OpenTween:Play()--Play the tween
end
function Close()
local CloseGoal = {}
CloseGoal .Value = HingeCloseCF
local CloseTween = TS:Create(CFrameValue,TweenInfo.new(doorOpenTime),OpenGoal)
CloseTween:Play()--play the tween
end
and now we have a simple working door . However, lets make it dynamic . Dynamic as in when the player open the door, the door will never come swinging into their face. To make this , we will need to use dot product(kinda hard to learn ngl xD). So in theory , when the player is 90 degree Infront of the door, the dot product should be 1 , when the player is 90 degree behind the door, the dot product should be -1 . So if the player is 180 degrees Infront the door , the dot product will be higher than 0 while if the player is 180 degrees behind the door , the dot product will be lower than 0
function GetDotProduct(doorCF,CharCF)
local DoorPosToCharPos = (doorCF.Position - CharCF.Position).Unit
local DoorLookVector = doorCF.LookVector
local Dot = doorLookVector(DoorPosTOCharPos)
return Dot > 0 and 1 or -1 -- basicall check if dot is bigger than 0 . if it is , it will return 1 . Else, it will return -1
end
splendid! So to change the direction of the rotation of the door when open, we can use this scirpt
local DoorOpenAngle = DoorOpenAngle * GetDotProduct(Door.CFrame,Char.HumanoidRootPart.CFrame)
Now , here is the free model
you can open settings to change some settings base on your own liking
Do not delete anything that is called Base ,Root ,Hinge ,Frame ,Door and the scripts
you can delete any descendance of Frame and Door
you can anchore/unachore the model as the script will handle the anchoring of the model
you can steal the free model without giving me credit but please understand the script <3
open for any suggestions to improve the door :>