mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:51:55 +00:00
working elevator doors, need to figure out a lerp formula for having the doors open while the elevator is moving
This commit is contained in:
@@ -46,12 +46,13 @@ type Impl_Static_Props = {
|
||||
LanternChimeDirection: rbxassetid,
|
||||
LanternChimeLanding: rbxassetid,
|
||||
FloorLevelingDistance: number,
|
||||
DoorOpeningDistance: number,
|
||||
LeveledDistance: number,
|
||||
__Moving: boolean,
|
||||
__CurrentFloor: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ButtonsTags: Tags.ElevatorButtons, LanternsTags: Tags.Lanterns) -> ClassConstructor
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor, ButtonsTags: Tags.ElevatorButtons, LanternsTags: Tags.Lanterns, LandingDoors: Tags.LandingTags) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
MOConstructor: MovingObjects.MovingObjectsConstructor,
|
||||
@@ -84,6 +85,7 @@ local Otis1960 = {} :: Impl_Constructor
|
||||
Otis1960.__index = Otis1960
|
||||
|
||||
Otis1960.FloorLevelingDistance = 2.5
|
||||
Otis1960.DoorOpeningDistance = Otis1960.FloorLevelingDistance/2.8
|
||||
Otis1960.LeveledDistance = 0.5
|
||||
Otis1960.Responsiveness = 50
|
||||
Otis1960.MaxVelocity = 10
|
||||
@@ -103,18 +105,17 @@ local ButtonFunctions: ButtonFunctions = {
|
||||
|
||||
[Enums.ButtonTree.Car] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
|
||||
local DecodedFloor = Tags.Decoders.CarTag(ButtonName)
|
||||
if not DecodedFloor then
|
||||
|
||||
if DecodedFloor then
|
||||
local Prompt = PromptModule.constructor(ButtonTree.Prompt :: ProximityPrompt, ButtonTree.Inst :: Instance)
|
||||
|
||||
Prompt:AddHookTriggered(function(Player: Player)
|
||||
if DecodedFloor then
|
||||
local _ButtonThread = ButtonsConstructor:AestheticActivateButton(ButtonTree.Inst :: BasePart, false, Otis1960.ButtonActivatedColor)
|
||||
self:GoToLevel(DecodedFloor)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local Prompt = PromptModule.constructor(ButtonTree.Prompt, ButtonTree.Inst)
|
||||
|
||||
Prompt:AddHookTriggered(function(Player: Player)
|
||||
if DecodedFloor then
|
||||
local _ButtonThread = ButtonsConstructor:AestheticActivateButton(ButtonTree.Inst :: BasePart, false, Otis1960.ButtonActivatedColor)
|
||||
self:GoToLevel(DecodedFloor)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
||||
[Enums.ButtonTree.Special] = function(self, ButtonName, ButtonsConstructor, ButtonTree)
|
||||
@@ -141,7 +142,7 @@ local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTag
|
||||
end
|
||||
end
|
||||
|
||||
function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags)
|
||||
function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
|
||||
local self = {} :: Constructor_Return_Props
|
||||
self.ElevatorBox_1960 = TagsConstructor:Request("ElevatorMover_1960") :: UnionOperation
|
||||
self.ElevatorDoor1 = TagsConstructor:Request("ElevatorDoor_1960_1") :: BasePart
|
||||
@@ -173,7 +174,7 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags)
|
||||
self.BoxAlignPosition,
|
||||
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Otis1960.Responsiveness, Otis1960.MaxVelocity)
|
||||
|
||||
self.ElevatorDoors = Doors.constructor(self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
|
||||
self.ElevatorDoors = Doors.constructor(LandingDoors, self.ElevatorBox_1960, self.ElevatorDoor1, self.ElevatorDoor2, self.ElevatorDoorSensor)
|
||||
self.TractionRopes = TractionRopes.constructor(self.Ropes, self.ElevatorBox_1960, Leveling)
|
||||
|
||||
--Buttons
|
||||
@@ -183,6 +184,11 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags)
|
||||
local ClassConstructor = setmetatable(self, Otis1960)
|
||||
HookButtons(ClassConstructor, ButtonsConstructor, Enums.ButtonTree.Car)
|
||||
|
||||
--Open the elevator doors on server start
|
||||
task.spawn(function()
|
||||
self.ElevatorDoors:ToggleElevatorDoors(true, 1)
|
||||
end)
|
||||
|
||||
print("🔝 Otis1960 initialized and ready")
|
||||
return ClassConstructor
|
||||
end
|
||||
@@ -203,7 +209,10 @@ local function FloorLeveled(self: ClassConstructor, RequestedLevel: number)
|
||||
end
|
||||
|
||||
function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
local RotationDelta = 0
|
||||
self.ElevatorDoors:ToggleElevatorDoors(false, Otis1960.__CurrentFloor)
|
||||
|
||||
local Delta = 0
|
||||
local DoorsOpeningEvent = false
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
|
||||
if self.__MovingConnection and self.__MovingConnection.Connected then
|
||||
@@ -220,30 +229,38 @@ function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||
|
||||
--Otis1960_ShaftGovernor
|
||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt) --Not safe for parallel
|
||||
RotationDelta+=1
|
||||
Delta+=1
|
||||
Otis1960.__Moving = true
|
||||
|
||||
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
||||
local ElevatorPositionY: number = ElevatorPosition.Y
|
||||
local BoxAlignY: number = self.BoxAlignPosition.Position.Y
|
||||
local ElevatorVelocityY: number = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
|
||||
self.MOConstructor:Frame_Pullies(RotationDelta, ElevatorVelocityY)
|
||||
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
|
||||
self.TractionRopes:Move(26.3, ElevatorPosition)
|
||||
|
||||
--Kill the connection
|
||||
if GoingUp then
|
||||
if ElevatorPosition.Y>=self.BoxAlignPosition.Position.Y-Otis1960.FloorLevelingDistance then
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.FloorLevelingDistance then
|
||||
FloorLeveling(self, RequestedLevel)
|
||||
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance and not DoorsOpeningEvent then
|
||||
print("fired")
|
||||
DoorsOpeningEvent = true
|
||||
self.ElevatorDoors:ToggleElevatorDoors(true, RequestedLevel)
|
||||
end
|
||||
end
|
||||
|
||||
if ElevatorPosition.Y>=self.BoxAlignPosition.Position.Y-Otis1960.LeveledDistance then
|
||||
if ElevatorPositionY>=BoxAlignY-Otis1960.LeveledDistance then
|
||||
FloorLeveled(self, RequestedLevel)
|
||||
end
|
||||
else
|
||||
if ElevatorPosition.Y<=self.BoxAlignPosition.Position.Y+Otis1960.FloorLevelingDistance then
|
||||
if ElevatorPositionY<=BoxAlignY+Otis1960.FloorLevelingDistance then
|
||||
FloorLeveling(self, RequestedLevel)
|
||||
end
|
||||
|
||||
if ElevatorPosition.Y<=self.BoxAlignPosition.Position.Y+Otis1960.LeveledDistance then
|
||||
if ElevatorPositionY<=BoxAlignY+Otis1960.LeveledDistance then
|
||||
FloorLeveled(self, RequestedLevel)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user