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

How do I make something move like a door?

Asked by 8 years ago

Hello! I'm trying to make the hood on my truck to move, and I've tried everything! I need some help but I found out I needed fake hinges to make it move like a door. But I can't script good! Can I get some help?

0
You should be able to use this for a ref, https://www.youtube.com/watch?v=YgbtGgQZ0oc User#5423 17 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

You could try Motor6D's. Although this can be acomplished via Scripting, I am unaware how to. So I use this plugin called Motor6D Maker

And now onto how to script it.

--Lets say it is in a part called "Anchor"
local partA = script.Parent.Anchor --Needs to be anchored

local partB = script.Parent.Hood --Needs to be unanchored

local partC = script.Parent.Pivot --Needs to be anchored

local cd = script.Parent.CD.ClickDetector

local open = false

cd.MouseClick:connect(function(playerWhoClicked)
    if open then
        partA.Motor.DesiredAngle = math.Rad(0) --0 Degrees to close it
        open = not open
    else
        partA.Motor.DesiredAngle = math.Rad(30) --30 Degrees to open it.
        open = not open
    end
end)

Notes -Everything is done in radians -The part pivots along the Pivot's Z Axis

This has not been tested so there might be a few bugs __________________________________________________________________________- TheHospitalDev

Ad
Log in to vote
0
Answered by
iDemum 0
8 years ago
Edited 8 years ago
Door                    = script.Parent -- Main model
Haha                    = Door.DoraTheExplorer -- The submodel that rotates 
Haha.PrimaryPart        = Haha.Hinge -- The hinge of the door inside the submodel DoraTheExplorer
fps                     = 60 -- The smaller the faster
opening                 = false
upen                    = false

function rotate(model, amount)
    for i=1, math.abs(amount/2) do
        model:SetPrimaryPartCFrame(model.Hinge.CFrame * CFrame.fromEulerAnglesXYZ(0,math.pi/amount,0))
        wait()
    end 
end

function open()
    if not opening then
        opening = true
        if upen then
            rotate(Haha, fps)
        else
            rotate(Haha, -fps)
        end
        upen = not upen
        opening = false
    else
    end
end

Answer this question