Limiting Radians (door)

38 views Asked by At

I cant figure out how to limit the radian angle to 90 degrees (~1.5 radians) in both directions from its base starting position

I'm trying to make phasmophobia style door, and expecting for it to limit 90 degrees and not go 360 through the hinge

https://imgur.com/a/JmsLj35 this is what I have made so far This is the current code in the video:

local UIS=game:GetService("UserInputService");
local HoldingDoor = false

UIS.InputBegan:Connect(function(input)
    if input.KeyCode==Enum.KeyCode.E then
    
        HoldingDoor = true
    end
end)

UIS.InputEnded:Connect(function(input)
    if input.KeyCode==Enum.KeyCode.E then
        HoldingDoor = false
    end
end)

local Door = workspace:WaitForChild("DoorHingeTest"):WaitForChild("Door")
local Interactor = script.Parent:WaitForChild("HumanoidRootPart")

while true do task.wait()
    if HoldingDoor then
    local Pivot = Door:GetPivot()
    local DisPlaced = Interactor.Position + Interactor.CFrame.LookVector * 2.5
    local Direction = (DisPlaced - Pivot.Position)  * 2
    
    local angle = math.atan2(Direction.Z, -Direction.X) 
    Door:PivotTo(CFrame.new(Pivot.Position) *  CFrame.Angles(0, angle, 0))
    end
end

I have tried clamping the angle, while it works on some orientations it does not for all, since 3.14 turns into -3.14 its difficult for me to figure out how to clamp that other than clamping I have no idea how to make it

0

There are 0 answers