Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Making a rotated brick grow only one one side?

Asked by
KoreanBBQ 301 Moderation Voter
8 years ago

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

0
I googled some stuff I think it has to do with logarithms, anyone help? I have no idea what it is KoreanBBQ 301 — 8y
0
Why not just translating it to the side? Or use a block mesh and have the Scale & Offset properties manipulated quickly? Redbullusa 1580 — 8y
0
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 KoreanBBQ 301 — 8y
0
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. Redbullusa 1580 — 8y
View all comments (2 more)
0
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 KoreanBBQ 301 — 8y
0
Are you talking about turning a square into a trapezoid? JasonTheOwner 391 — 8y

1 answer

Log in to vote
-1
Answered by 8 years ago

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)
    --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)

0
No I've made better doors that that in the past, and I dont want them to only slide, I also want them to resize KoreanBBQ 301 — 8y
0
Alrighty - I'll put a free model together of one that resizes. I was going to go with a resizing idea, when I did this one, but decided to go with a slider. Keep in mind, that door is all about the scripting - you can design it however you want LOL JasonTheOwner 391 — 8y
0
What if it rotated open like a garage door? You really want it to resize right? JasonTheOwner 391 — 8y
0
Nevermind I put a new set of code together that I tested and it seems to work. JasonTheOwner 391 — 8y
Ad

Answer this question