Free model is here
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)
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
local Look = (Direction).unit
local ray = Ray.new(obj1.CFrame.p, Look*500)
local ignorelist = {}
table.insert(ignorelist,obj1)
local part3, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,ignorelist)
print("part found: "..part3.Name)
max_size = (part3.Position- obj1.CFrame.p).magnitude + 2
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)
6 comments
I googled some stuff I think it has to do with logarithms, anyone help? I have no idea what it is
Why not just translating it to the side? Or use a block mesh and have the Scale & Offset properties manipulated quickly?
I can't translate it to the side because then you would see it through the other side. And Offsets with Meshes work just like Scale, it wouldn't help because it resizes on bot sides
Offset's different from Scale. Offset translate it while Scale resizes it. If you use both of them at the same time, it'll simulate a "grow" or "shrink" effect.
Oh yeah you're right I could use Offset but I'd rather have the actual object to move, because it could mess up with some Touched events or stuff like that
Are you talking about turning a square into a trapezoid?