Hello, I'm trying to make some kind of trapdoor,
The way it works is like this:
When you close it, it kind of slides and grows so that you have the impression it is closing. A little like a garage door but on the ground.
I'm trying to find the exact formula to make it look good.
So far I have :
h1.Size=Vector3.new(h1.Size.X+.482,h1.Size.Y,h1.Size.Z) h1.CFrame=CFrame.new(q1.X-.241,q1.Y,q1.Z+.0241)*CFrame.Angles(math.rad(0),math.rad(15),math.rad(-0))
But that wont work.
h1 being the door part and q1 being its position
Here's some code that should work.
Note - use the Front Surface as the edge of the door that closes, and increment must be greater than one. I used 1.01
Put this in a server script...
New Answer:
function difference(n1,n2) return math.abs(n2-n1) end function invertFace(face) if face == Enum.NormalId.Front then return Enum.NormalId.Back elseif face == Enum.NormalId.Back then return Enum.NormalId.Front elseif face == Enum.NormalId.Top then return Enum.NormalId.Bottom elseif face == Enum.NormalId.Bottom then return Enum.NormalId.Top elseif face == Enum.NormalId.Left then return Enum.NormalId.Right elseif face == Enum.NormalId.Right then return Enum.NormalId.Left end end function getPositiveFace(face) if face == Enum.NormalId.Top or face == Enum.NormalId.Right or face == Enum.NormalId.Back then return face else return invertFace(face) end end function getFacePosition(object,face) return ((object.CFrame * CFrame.new(object.Size/2 * Vector3.FromNormalId(face))).p * Vector3.FromNormalId(getPositiveFace(face))).magnitude end lastDistR = 0 lastDistL = 0 lastDistF = 0 lastDistB = 0 lastDistT = 0 lastDistB2 = 0 function closeDoor(part,side, distance) --local part = handles.Adornee if part == nil then return end if tostring(side) == "Enum.NormalId.Front" then if distance - lastDistF > 1 then local newDist = math.floor(distance - lastDistF) local cf = part.CFrame local lv = cf.lookVector local cf2 = part.CFrame local size = part.Size part.Size = Vector3.new(part.Size.x, part.Size.y, part.Size.z + newDist) if part.Size == size then part.CFrame = cf2 + lv * (0.5*newDist) cf2 = part.CFrame end part.CFrame = cf2 + lv * (0.5*newDist) lastDistF = lastDistF + newDist else if distance - lastDistF < -1 and part.Size.z + math.ceil(distance - lastDistF) < 1 then local newDist = -(part.Size.z - 1) local cf = part.CFrame local lv = cf.lookVector local cf2 = part.CFrame local size = part.Size part.Size = Vector3.new(part.Size.x, part.Size.y, part.Size.z + newDist) if part.Size == size then part.CFrame = cf2 + lv * (0.5*newDist) cf2 = part.CFrame end part.CFrame = cf2 + lv * (0.5*newDist) lastDistF = lastDistF + newDist else if distance - lastDistF < -1 and part.Size.z + math.ceil(distance - lastDistF) > 0 then local newDist = math.ceil(distance - lastDistF) local cf = part.CFrame local lv = cf.lookVector local cf2 = part.CFrame local size = part.Size part.Size = Vector3.new(part.Size.x, part.Size.y, part.Size.z + newDist) if part.Size == size then part.CFrame = cf2 + lv * (0.5*newDist) cf2 = part.CFrame end part.CFrame = cf2 + lv * (0.5*newDist) lastDistF = lastDistF + newDist end end end end end local increment = 1.01 local max_size = 10 local obj1 = script.Parent local eye = script.Parent.Parent.eye local face1 = Enum.NormalId.Front local Direction = obj1.CFrame.lookVector --+ Vector3.new(0,0,0) local Look = (Direction).unit --for whatever reason -90 had to be changed to 90 local ray = Ray.new(obj1.CFrame.p, Look*500) -- -5 to clear the entrance ramp elevator with the ray and * 300 is the distance of the ray - you must be this close to the ground local ignorelist = {} table.insert(ignorelist,obj1) -- table.insert(ignorelist,eye) local part3, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignorelist) print("part found: "..part3.Name) max_size = (part3.Position- obj1.CFrame.p).magnitude + 2 --max_size = max_size + (obj1.Size/2 * Vector3.FromNormalId(Enum.NormalId.Back)).magnitude print("max_size: "..max_size) local function ontouched(hit) if hit.Parent:FindFirstChild("Humanoid") then local total = 0 while total < max_size do closeDoor(obj1,face1,(increment*-1.0)) lastDistF = 0 wait(.001) total = total + increment end wait(5) local total = 0 while total < max_size do closeDoor(obj1,face1,increment) lastDistF = 0 wait(.001) total = total + increment end wait(5) end end script.Parent.Touched:connect(ontouched)