Just so you know, this is a request. For it not to be, you need to provide your own attempt at doing this, and we will correct it for you.
This is, however, also a trivial question, so here you go:
You can do this using CFrame and Size changing, which will give accurate collision, but if you already have the code working to have the door itself slide open, and just want to fix the visual, you can use a SpecialMesh with the 'Brick' MeshType.
You set the Scale property to Vector3.new(X, 1, 1), assuming 'X' is the axis the door is 'closing' on. X itself is whatever percentage the door is open.
If, for example, the door takes five seconds to close or open, that would look like this:
door.Mesh.Scale = Vector3.new(t/5, 1, 1)
For opening or this:
door.Mesh.Scale = Vector3.new(1 - t/5, 1, 1)
For closing.
Where t is the elapsed time since the door was 'opened' (or 5 if t > 5).
This will shrink the door evenly, however, which is not desired.
In order to fix this, we need to set the Offset of the Mesh to half of the scaled size of the door:
door.Mesh.Offset = Vector3.new(0.5*door.Size.X*(1 - door.Mesh.Scale.X), 0, 0)
(If this 'closes' in the wrong direction, simply change the 0.5 to -0.5)
I assume you know how to use 't' in the above two snippets, but you might be doing it slower than is possible, and for anyone that doesn't know, here is a full code block with functions to open and close the door with the best smoothness possible from a Script (as opposed to a LocalScript).
local RunService = game:GetService("RunService")
local isOpen = false
local deb = false
local dur = 5
function toggleDoor()
if deb then return end
deb = true
local st = tick()
while true do
local t = tick() - st
if t > dur then t = dur end
if isOpen then
door.Mesh.Scale = Vector3.new(1 - t/dur, 1, 1)
else
door.Mesh.Scale = Vector3.new(t/dur, 1, 1)
end
door.Mesh.Offset = Vector3.new(0.5*door.Size.X*(1- door.Mesh.Scale.X), 0, 0)
if t >= dur then break end
RunService.Heartbeat:wait()
end
deb = false
isOpen = not isOpen
end
4 comments
LUA
Oh yeah, good idea, I never though about scripting it...
essentially what you want to do is resize the object 1st, and then move it based on its new size (also relative to the position of the "edge" of class it is hitting). not too complicated
I was mocking your bio.