mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
algebra function and work on floor placements
This commit is contained in:
@@ -8,7 +8,9 @@ local Storage: ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Main = script.Parent.Parent.Parent
|
||||
local Load = Main:WaitForChild("Load")
|
||||
|
||||
local Tween = require(Storage:WaitForChild("Tween"))
|
||||
local Tween = require(Storage:WaitForChild("Tween"))
|
||||
local Algebra = require(Storage:WaitForChild("Algebra"))
|
||||
|
||||
local Tags = require(Load:WaitForChild("Tags"))
|
||||
local SoundEnums = require(Main:WaitForChild("Enums"):WaitForChild("Sounds"))
|
||||
|
||||
@@ -173,7 +175,7 @@ local function DoorsAnimationFloor(FloorDoors: {Instance?}, Floor: number, openi
|
||||
return Door1Tween_Floor, Door2Tween_Floor
|
||||
end
|
||||
|
||||
local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, opening: boolean?, activated_via_censor: boolean?): (Tween?, Tween?)
|
||||
local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, opening: boolean, activated_via_censor: boolean?)
|
||||
--Roblox physics will freak out
|
||||
self.ElevatorDoor1.CanCollide = false
|
||||
self.ElevatorDoor2.CanCollide = false
|
||||
@@ -181,13 +183,12 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
|
||||
local ElevatorDoor1_P: Vector3 = self.ElevatorDoor1.Position
|
||||
local ElevatorDoor2_P: Vector3 = self.ElevatorDoor2.Position
|
||||
|
||||
if opening then
|
||||
--This is mega cringe but the doors can open while the elevator is moving now
|
||||
local StartTime = os.clock()
|
||||
local Timing = Doors.ElevatorDoorTime-1
|
||||
local StartTime = os.clock()
|
||||
local Timing = Doors.ElevatorDoorTime-1
|
||||
|
||||
if opening then
|
||||
while task.wait() do
|
||||
local Time = math.clamp((os.clock()-StartTime)/Timing, 0, 1)
|
||||
local Time = Algebra.LinearElapse(StartTime, Timing)
|
||||
|
||||
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
||||
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
||||
@@ -201,45 +202,21 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
|
||||
end
|
||||
end
|
||||
else
|
||||
local Door1Tween = self.DoorTween1:Start(nil, {
|
||||
Position = ElevatorDoor1_P+Doors.Door1Stopped_X
|
||||
}, TweenInfo.new(
|
||||
Doors.ElevatorDoorTime,
|
||||
activated_via_censor and Enum.EasingStyle.Linear or Doors.ElevatorDoorStyle,
|
||||
Enum.EasingDirection.Out
|
||||
))
|
||||
while task.wait() do
|
||||
local Time = Algebra.LinearElapse(StartTime, Timing)
|
||||
|
||||
local Door2Tween = self.DoorTween2:Start(nil, {
|
||||
Position = ElevatorDoor2_P+Doors.Door2Stopped_X
|
||||
}, TweenInfo.new(
|
||||
Doors.ElevatorDoorTime,
|
||||
activated_via_censor and Enum.EasingStyle.Linear or Doors.ElevatorDoorStyle,
|
||||
Enum.EasingDirection.Out
|
||||
))
|
||||
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
||||
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
||||
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
|
||||
|
||||
if Doors.__DoorSensors and Doors.__DoorSensors.Connected then
|
||||
Doors.__DoorSensors:Disconnect()
|
||||
end
|
||||
Doors.__DoorSensors = self:__DetectSensorHit(Door1Tween, Door2Tween)
|
||||
|
||||
--Door clicking noise
|
||||
task.delay(Doors.ElevatorDoorTime-.90, function()
|
||||
--is the door close enough to closing?
|
||||
if (Doors.Door2Stopped_X-ElevatorDoor2_P).X-self.ElevatorDoor2.Position.X>10 then
|
||||
self.DoorClosingClick:Play()
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector+Doors.Door1Stopped_X, Time)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector+Doors.Door2Stopped_X, Time)
|
||||
|
||||
if Time>=1 then
|
||||
break
|
||||
end
|
||||
end)
|
||||
|
||||
if Door2Tween then
|
||||
Door2Tween.Completed:Wait()
|
||||
elseif Door1Tween then
|
||||
Door1Tween.Completed:Wait()
|
||||
end
|
||||
|
||||
return Door1Tween, Door2Tween
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local raycastParams = RaycastParams.new()
|
||||
@@ -296,9 +273,8 @@ function Doors:ToggleElevatorDoorsAsync<T,U>(opening, floor)
|
||||
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
|
||||
end
|
||||
|
||||
local _Door2Tween, _Door1Tween = ElevatorDoorsAnimationAsync(self, opening)
|
||||
|
||||
Attributes.Relay.Open.Value = opening ~= nil and opening
|
||||
Attributes.Relay.Open.Value = opening
|
||||
ElevatorDoorsAnimationAsync(self, opening)
|
||||
|
||||
self.ElevatorDoor1.CanCollide = true
|
||||
self.ElevatorDoor2.CanCollide = true
|
||||
|
||||
@@ -107,9 +107,7 @@ function Relay:__GoalYLevel()
|
||||
end
|
||||
|
||||
function Relay:__Goal()
|
||||
local Level: number? = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value]
|
||||
|
||||
self.ElevatorAttributes.Relay.GoalYLevel.Value = Level or self.LevelingModule.Leveling[1] :: number
|
||||
self.ElevatorAttributes.Relay.GoalYLevel.Value = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value] or self.LevelingModule.Leveling[1] :: number
|
||||
end
|
||||
|
||||
function Relay:BulkConnect()
|
||||
@@ -117,7 +115,7 @@ function Relay:BulkConnect()
|
||||
local OpenRelay = self.DoorAttributes.Relay.Open
|
||||
|
||||
self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value)
|
||||
self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value, false)
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Ready()
|
||||
@@ -125,7 +123,7 @@ function Relay:BulkConnect()
|
||||
end)
|
||||
|
||||
self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
self.PhysicalRelay:SetState("DO", OpenRelay.Value)
|
||||
self.PhysicalRelay:SetState("DO", OpenRelay.Value, true)
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Open()
|
||||
|
||||
@@ -95,7 +95,7 @@ end
|
||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
return not self.ElevatorAttributes.Relay.ReadyForMoving.Value
|
||||
return not self.ElevatorAttributes.Relay.ReadyForMoving.Value and self.DoorAttributes.Relay.Open.Value
|
||||
end
|
||||
|
||||
return RelayAlgorithm
|
||||
@@ -450,6 +450,7 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
self.PhysicalRelays:SetState("440 V", true, false)
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
|
||||
--task.wait(1)
|
||||
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
|
||||
Delta+=1
|
||||
|
||||
|
||||
@@ -23,16 +23,17 @@ export type Scalar = {
|
||||
}
|
||||
|
||||
export type Math = {
|
||||
Linear: LinearFunction,
|
||||
InOutBack: EaseFunction,
|
||||
OutBounce: EaseFunction,
|
||||
InQuad: EaseFunction,
|
||||
IsOdd: (n: number) -> boolean,
|
||||
IsEven: (n: number) -> boolean,
|
||||
Linear: LinearFunction,
|
||||
InOutBack: EaseFunction,
|
||||
OutBounce: EaseFunction,
|
||||
InQuad: EaseFunction,
|
||||
IsOdd: (n: number) -> boolean,
|
||||
IsEven: (n: number) -> boolean,
|
||||
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
|
||||
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar,
|
||||
maxmin: (min: number, n: number, max: number) -> number,
|
||||
minmax: (min: number, n: number, max: number) -> number
|
||||
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar,
|
||||
LinearElapse: (StartTime: number, Timing: number) -> number,
|
||||
maxmin: (min: number, n: number, max: number) -> number,
|
||||
minmax: (min: number, n: number, max: number) -> number
|
||||
}
|
||||
|
||||
local Math = {} :: Math
|
||||
@@ -51,7 +52,7 @@ end
|
||||
|
||||
Math.minmax = Math.maxmin
|
||||
|
||||
function Math.RotationMatrix(X: number, Y: number, Z: number): RotationMatrix
|
||||
function Math.RotationMatrix(X, Y, Z)
|
||||
local cosX, sinX = math.cos(X), math.sin(X)
|
||||
local cosY, sinY = math.cos(Y), math.sin(Y)
|
||||
local cosZ, sinZ = math.cos(Z), math.sin(Z)
|
||||
@@ -66,7 +67,7 @@ function Math.RotationMatrix(X: number, Y: number, Z: number): RotationMatrix
|
||||
}
|
||||
end
|
||||
|
||||
function Math.Scalar(X1: number, Y1: number, X2: number, Y2: number): Scalar
|
||||
function Math.Scalar(X1, Y1, X2, Y2)
|
||||
local dX, dY = X1-X2, Y1-Y2
|
||||
return {
|
||||
Distance = math.sqrt(dX*dX+dY*dY),
|
||||
@@ -75,8 +76,12 @@ function Math.Scalar(X1: number, Y1: number, X2: number, Y2: number): Scalar
|
||||
}
|
||||
end
|
||||
|
||||
function Math.LinearElapse(StartTime, Timing)
|
||||
return math.clamp((os.clock()-StartTime)/Timing, 0, 1)
|
||||
end
|
||||
|
||||
--My versions
|
||||
function Math.Linear(a,b,t)
|
||||
function Math.Linear(a, b, t)
|
||||
return a-a*t+b*t
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user