mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:51:55 +00:00
Spinning objects
This commit is contained in:
@@ -8,6 +8,7 @@ local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local RS: RunService = game:GetService("RunService")
|
||||
|
||||
local TagsModule = require(Storage:WaitForChild("Tags"))
|
||||
local Easings = require(Storage:WaitForChild("AlgebraEasings"))
|
||||
|
||||
local Leveling = require(script:WaitForChild("Leveling"))
|
||||
local Doors = require(script:WaitForChild("Doors"))
|
||||
@@ -19,13 +20,14 @@ local ButtonTags = require(Elevators:WaitForChild("Buttons"))
|
||||
local TractionRopes = require(Elevators:WaitForChild("TractionRopes"))
|
||||
|
||||
type Tags = TagsModule.ExportedTags
|
||||
type TagsConstructor = TagsModule.TagsConstructor
|
||||
|
||||
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
|
||||
type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
__MoveFloors: (self: ClassConstructor, Level: number) -> (),
|
||||
_MoveFloors: (self: ClassConstructor, Level: number) -> (),
|
||||
GoToLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
||||
} & Impl_Static_Props
|
||||
|
||||
@@ -35,14 +37,13 @@ type Impl_Static_Props = {
|
||||
MaxVelocity: number
|
||||
}
|
||||
|
||||
type Constructor_Fun = (Tags: Tags) -> ClassConstructor
|
||||
type Constructor_Fun = (TagsConstructor: TagsConstructor) -> ClassConstructor
|
||||
type Constructor_Return_Props = {
|
||||
Tags: Tags,
|
||||
ElevatorBox_1960: UnionOperation,
|
||||
ElevatorDoor1: BasePart,
|
||||
ElevatorDoor2: BasePart,
|
||||
ElevatorDoorSensor: Folder,
|
||||
ProximityButtons: {Instance},
|
||||
BoxAttachment: Attachment,
|
||||
BoxAlignPosition: AlignPosition,
|
||||
BoxAlignOrientation: AlignOrientation,
|
||||
@@ -50,9 +51,16 @@ type Constructor_Return_Props = {
|
||||
Ropes: {Instance},
|
||||
TractionRopes: TractionRopes.TractionRopesConstructor,
|
||||
PiePlateSelector: UnionOperation,
|
||||
__RopeConnection: RBXScriptConnection?
|
||||
Pulley: UnionOperation,
|
||||
Pulley2: UnionOperation,
|
||||
Governor: UnionOperation,
|
||||
GovernorFlyballs: UnionOperation,
|
||||
PieplatePulley: UnionOperation,
|
||||
__MovingConnection: RBXScriptConnection?
|
||||
}
|
||||
|
||||
type ButtonFunction = () -> ()
|
||||
|
||||
local Otis1960 = {} :: Impl_Constructor
|
||||
Otis1960.__index = Otis1960
|
||||
|
||||
@@ -82,6 +90,20 @@ local function ButtonPress(Button: BasePart, Activated: boolean)
|
||||
end)
|
||||
end
|
||||
|
||||
local ButtonFunctions: {[Enums.EnumButtonTree]: ButtonFunction} = {
|
||||
[Enums.ButtonTree.Landing] = function()
|
||||
|
||||
end,
|
||||
|
||||
[Enums.ButtonTree.Car] = function()
|
||||
|
||||
end,
|
||||
|
||||
[Enums.ButtonTree.Special] = function()
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTags.ButtonsConstructor, ButtonType: Enums.EnumValue)
|
||||
for ButtonNameType, ButtonList in ButtonsConstructor.Buttons do
|
||||
for ButtonName, ButtonTree in ButtonList do
|
||||
@@ -118,19 +140,23 @@ local function HookButtons(self: ClassConstructor, ButtonsConstructor: ButtonTag
|
||||
end
|
||||
end
|
||||
|
||||
function Otis1960.constructor(Tags)
|
||||
function Otis1960.constructor(TagsConstructor)
|
||||
local self = {} :: Constructor_Return_Props
|
||||
self.Tags = Tags
|
||||
self.ElevatorBox_1960 = Tags.ElevatorMover_1960 :: UnionOperation
|
||||
self.ElevatorDoor1 = Tags.ElevatorDoor_1960_1 :: BasePart
|
||||
self.ElevatorDoor2 = Tags.ElevatorDoor_1960_2 :: BasePart
|
||||
self.ElevatorDoorSensor = Tags.ElevatorDoor_Sensor_1960 :: Folder
|
||||
self.ProximityButtons = Tags.ProximityElevatorButton :: {Instance}
|
||||
self.Ropes = Tags["1960_ElevatorPulleyRope"] :: {Instance}
|
||||
self.PiePlateSelector = Tags.Otis1960_PiePlateSelector :: UnionOperation
|
||||
self.PiePlatePlates = Tags.Otis1960_PiePlatePlates :: UnionOperation
|
||||
self.WheelRotation = Tags.WheelRotation :: {Instance}
|
||||
self.ElevatorBox_1960 = TagsConstructor:Request("ElevatorMover_1960") :: UnionOperation
|
||||
self.ElevatorDoor1 = TagsConstructor:Request("ElevatorDoor_1960_1") :: BasePart
|
||||
self.ElevatorDoor2 = TagsConstructor:Request("ElevatorDoor_1960_2") :: BasePart
|
||||
self.ElevatorDoorSensor = TagsConstructor:Request("ElevatorDoor_Sensor_1960") :: Folder
|
||||
self.Ropes = TagsConstructor:Request("1960_ElevatorPulleyRope") :: {Instance}
|
||||
self.PiePlateSelector = TagsConstructor:Request("Otis1960_PiePlateSelector") :: UnionOperation
|
||||
self.PiePlatePlates = TagsConstructor:Request("Otis1960_PiePlatePlates") :: UnionOperation
|
||||
|
||||
--Rotation objects
|
||||
self.Pulley = TagsConstructor:Request("Otis1960_Pulley") :: UnionOperation
|
||||
self.Pulley2 = TagsConstructor:Request("Otis1960_Pulley2") :: UnionOperation
|
||||
self.Governor = TagsConstructor:Request("Otis1960_Governor") :: UnionOperation
|
||||
self.GovernorFlyballs = TagsConstructor:Request("Otis1960_GovernorFlyballs") :: UnionOperation
|
||||
self.PieplatePulley = TagsConstructor:Request("Otis1960_PieplatePulley") :: UnionOperation
|
||||
|
||||
self.BoxAttachment,
|
||||
self.BoxAlignPosition,
|
||||
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Otis1960.Responsiveness, Otis1960.MaxVelocity)
|
||||
@@ -140,7 +166,7 @@ function Otis1960.constructor(Tags)
|
||||
self.PiePlate = PieplateModule.constructor(self.PiePlateSelector, self.PiePlatePlates, self.ElevatorBox_1960)
|
||||
|
||||
--Buttons
|
||||
local ButtonsConstructor = ButtonTags.constructor(Tags, Enums.Elevator.Otis1960)
|
||||
local ButtonsConstructor = ButtonTags.constructor(TagsConstructor, Enums.Elevator.Otis1960)
|
||||
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
|
||||
|
||||
local ClassConstructor = setmetatable(self, Otis1960)
|
||||
@@ -151,18 +177,54 @@ function Otis1960.constructor(Tags)
|
||||
return ClassConstructor
|
||||
end
|
||||
|
||||
function Otis1960:__MoveFloors(Level)
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
self.TractionRopes:Moving(Level, 26)
|
||||
--self.PiePlate:test()
|
||||
|
||||
function Otis1960:_MoveFloors(Level)
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
local RotationDelta = 0
|
||||
local PulleyPosition = self.Pulley.CFrame
|
||||
local GovernorPosition = self.Governor.CFrame
|
||||
local FlyballPosition = self.GovernorFlyballs.CFrame
|
||||
local Pulley2Position = self.Pulley2.CFrame
|
||||
local PieplatePulleyPosition = self.PieplatePulley.CFrame
|
||||
|
||||
local LastVelocityDelta = 0
|
||||
|
||||
if self.__MovingConnection then
|
||||
self.__MovingConnection:Disconnect()
|
||||
end
|
||||
--Otis1960_ShaftGovernor
|
||||
|
||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt) --Not safe for parallel
|
||||
RotationDelta+=1
|
||||
|
||||
local ElevatorPosition = self.ElevatorBox_1960.Position
|
||||
local ElevatorVelocity = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
local VelocitySmoothing = Easings.Linear(LastVelocityDelta, ElevatorVelocity, .5)
|
||||
LastVelocityDelta = ElevatorVelocity
|
||||
|
||||
local PullAngle_2 = math.rad(RotationDelta*VelocitySmoothing/2)
|
||||
local PullAngle = math.rad(RotationDelta*VelocitySmoothing)
|
||||
|
||||
self.Pulley.CFrame = PulleyPosition *CFrame.Angles(-PullAngle_2, 0, 0)
|
||||
self.Pulley2.CFrame = Pulley2Position *CFrame.Angles(PullAngle_2, 0, 0)
|
||||
self.Governor.CFrame = GovernorPosition *CFrame.Angles(0, PullAngle_2, 0)
|
||||
self.GovernorFlyballs.CFrame = FlyballPosition *CFrame.Angles(PullAngle, 0, 0)
|
||||
self.PieplatePulley.CFrame = PieplatePulleyPosition*CFrame.Angles(PullAngle_2, 0, 0)
|
||||
|
||||
self.TractionRopes:Move(26.3, ElevatorPosition)
|
||||
|
||||
if ElevatorPosition.Y>=self.BoxAlignPosition.Position.Y then
|
||||
(self.__MovingConnection :: RBXScriptConnection):Disconnect()
|
||||
print("Dead")
|
||||
end
|
||||
end)
|
||||
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, Level, ElevatorBoxCurrentPos.Z)
|
||||
end
|
||||
|
||||
function Otis1960:GoToLevel(RequestedLevel)
|
||||
local level: number = Leveling[RequestedLevel]
|
||||
if level and level ~= 0 then
|
||||
self:__MoveFloors(level)
|
||||
self:_MoveFloors(level)
|
||||
else
|
||||
warn(`[{Enums.Elevator.Otis1960}]: landing out of range! requested landing: {tostring(RequestedLevel)}`)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user