mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
algebra function and work on floor placements
This commit is contained in:
@@ -9,6 +9,8 @@ local Main = script.Parent.Parent.Parent
|
|||||||
local Load = Main:WaitForChild("Load")
|
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 Tags = require(Load:WaitForChild("Tags"))
|
||||||
local SoundEnums = require(Main:WaitForChild("Enums"):WaitForChild("Sounds"))
|
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
|
return Door1Tween_Floor, Door2Tween_Floor
|
||||||
end
|
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
|
--Roblox physics will freak out
|
||||||
self.ElevatorDoor1.CanCollide = false
|
self.ElevatorDoor1.CanCollide = false
|
||||||
self.ElevatorDoor2.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 ElevatorDoor1_P: Vector3 = self.ElevatorDoor1.Position
|
||||||
local ElevatorDoor2_P: Vector3 = self.ElevatorDoor2.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 StartTime = os.clock()
|
||||||
local Timing = Doors.ElevatorDoorTime-1
|
local Timing = Doors.ElevatorDoorTime-1
|
||||||
|
|
||||||
|
if opening then
|
||||||
while task.wait() do
|
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 ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
||||||
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local Door1Tween = self.DoorTween1:Start(nil, {
|
while task.wait() do
|
||||||
Position = ElevatorDoor1_P+Doors.Door1Stopped_X
|
local Time = Algebra.LinearElapse(StartTime, Timing)
|
||||||
}, TweenInfo.new(
|
|
||||||
Doors.ElevatorDoorTime,
|
|
||||||
activated_via_censor and Enum.EasingStyle.Linear or Doors.ElevatorDoorStyle,
|
|
||||||
Enum.EasingDirection.Out
|
|
||||||
))
|
|
||||||
|
|
||||||
local Door2Tween = self.DoorTween2:Start(nil, {
|
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
||||||
Position = ElevatorDoor2_P+Doors.Door2Stopped_X
|
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
||||||
}, TweenInfo.new(
|
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
|
||||||
Doors.ElevatorDoorTime,
|
|
||||||
activated_via_censor and Enum.EasingStyle.Linear or Doors.ElevatorDoorStyle,
|
|
||||||
Enum.EasingDirection.Out
|
|
||||||
))
|
|
||||||
|
|
||||||
if Doors.__DoorSensors and Doors.__DoorSensors.Connected then
|
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector+Doors.Door1Stopped_X, Time)
|
||||||
Doors.__DoorSensors:Disconnect()
|
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector+Doors.Door2Stopped_X, Time)
|
||||||
|
|
||||||
|
if Time>=1 then
|
||||||
|
break
|
||||||
end
|
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()
|
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
|
|
||||||
if Door2Tween then
|
|
||||||
Door2Tween.Completed:Wait()
|
|
||||||
elseif Door1Tween then
|
|
||||||
Door1Tween.Completed:Wait()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Door1Tween, Door2Tween
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local raycastParams = RaycastParams.new()
|
local raycastParams = RaycastParams.new()
|
||||||
@@ -296,9 +273,8 @@ function Doors:ToggleElevatorDoorsAsync<T,U>(opening, floor)
|
|||||||
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
|
DoorsAnimationFloor(FloorDoorsObjects, floor, opening)
|
||||||
end
|
end
|
||||||
|
|
||||||
local _Door2Tween, _Door1Tween = ElevatorDoorsAnimationAsync(self, opening)
|
Attributes.Relay.Open.Value = opening
|
||||||
|
ElevatorDoorsAnimationAsync(self, opening)
|
||||||
Attributes.Relay.Open.Value = opening ~= nil and opening
|
|
||||||
|
|
||||||
self.ElevatorDoor1.CanCollide = true
|
self.ElevatorDoor1.CanCollide = true
|
||||||
self.ElevatorDoor2.CanCollide = true
|
self.ElevatorDoor2.CanCollide = true
|
||||||
|
|||||||
@@ -107,9 +107,7 @@ function Relay:__GoalYLevel()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Relay:__Goal()
|
function Relay:__Goal()
|
||||||
local Level: number? = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value]
|
self.ElevatorAttributes.Relay.GoalYLevel.Value = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value] or self.LevelingModule.Leveling[1] :: number
|
||||||
|
|
||||||
self.ElevatorAttributes.Relay.GoalYLevel.Value = Level or self.LevelingModule.Leveling[1] :: number
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Relay:BulkConnect()
|
function Relay:BulkConnect()
|
||||||
@@ -117,7 +115,7 @@ function Relay:BulkConnect()
|
|||||||
local OpenRelay = self.DoorAttributes.Relay.Open
|
local OpenRelay = self.DoorAttributes.Relay.Open
|
||||||
|
|
||||||
self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
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
|
if not self.ElevatorAttributes.Stopped.Value then
|
||||||
self:__Ready()
|
self:__Ready()
|
||||||
@@ -125,7 +123,7 @@ function Relay:BulkConnect()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
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
|
if not self.ElevatorAttributes.Stopped.Value then
|
||||||
self:__Open()
|
self:__Open()
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ end
|
|||||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||||
self:RawInsert(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
|
end
|
||||||
|
|
||||||
return RelayAlgorithm
|
return RelayAlgorithm
|
||||||
@@ -450,6 +450,7 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
|||||||
self.PhysicalRelays:SetState("440 V", true, false)
|
self.PhysicalRelays:SetState("440 V", true, false)
|
||||||
self.MOConstructor:UpdateCFrame()
|
self.MOConstructor:UpdateCFrame()
|
||||||
|
|
||||||
|
--task.wait(1)
|
||||||
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
|
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
|
||||||
Delta+=1
|
Delta+=1
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export type Math = {
|
|||||||
IsEven: (n: number) -> boolean,
|
IsEven: (n: number) -> boolean,
|
||||||
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
|
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
|
||||||
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar,
|
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar,
|
||||||
|
LinearElapse: (StartTime: number, Timing: number) -> number,
|
||||||
maxmin: (min: number, n: number, max: number) -> number,
|
maxmin: (min: number, n: number, max: number) -> number,
|
||||||
minmax: (min: number, n: number, max: number) -> number
|
minmax: (min: number, n: number, max: number) -> number
|
||||||
}
|
}
|
||||||
@@ -51,7 +52,7 @@ end
|
|||||||
|
|
||||||
Math.minmax = Math.maxmin
|
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 cosX, sinX = math.cos(X), math.sin(X)
|
||||||
local cosY, sinY = math.cos(Y), math.sin(Y)
|
local cosY, sinY = math.cos(Y), math.sin(Y)
|
||||||
local cosZ, sinZ = math.cos(Z), math.sin(Z)
|
local cosZ, sinZ = math.cos(Z), math.sin(Z)
|
||||||
@@ -66,7 +67,7 @@ function Math.RotationMatrix(X: number, Y: number, Z: number): RotationMatrix
|
|||||||
}
|
}
|
||||||
end
|
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
|
local dX, dY = X1-X2, Y1-Y2
|
||||||
return {
|
return {
|
||||||
Distance = math.sqrt(dX*dX+dY*dY),
|
Distance = math.sqrt(dX*dX+dY*dY),
|
||||||
@@ -75,6 +76,10 @@ function Math.Scalar(X1: number, Y1: number, X2: number, Y2: number): Scalar
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Math.LinearElapse(StartTime, Timing)
|
||||||
|
return math.clamp((os.clock()-StartTime)/Timing, 0, 1)
|
||||||
|
end
|
||||||
|
|
||||||
--My versions
|
--My versions
|
||||||
function Math.Linear(a, b, t)
|
function Math.Linear(a, b, t)
|
||||||
return a-a*t+b*t
|
return a-a*t+b*t
|
||||||
|
|||||||
Reference in New Issue
Block a user