mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
actions module
This commit is contained in:
@@ -2,25 +2,120 @@
|
|||||||
--!native
|
--!native
|
||||||
--!strict
|
--!strict
|
||||||
|
|
||||||
local Actions = {
|
local Actions = {}
|
||||||
ActionCurrent = false,
|
|
||||||
Walk = 10,
|
|
||||||
Sneaking = 10/2 --10 is default
|
|
||||||
}
|
|
||||||
Actions.__index = Actions
|
Actions.__index = Actions
|
||||||
|
|
||||||
function Actions.constructor(HumanoidSettingsInherent, Humanoid: Humanoid)
|
--Sneak static properties
|
||||||
|
Actions.DoingAction = false
|
||||||
|
Actions.Sneaking = false
|
||||||
|
Actions.Crouching = false
|
||||||
|
Actions.Walk = 10
|
||||||
|
Actions.SneakingSpeed = 10/2 --10 is default
|
||||||
|
--Crouch static properties
|
||||||
|
Actions.Crouching = false
|
||||||
|
Actions.StandHeight = 2.1
|
||||||
|
Actions.CrouchHeight = .6
|
||||||
|
Actions.WalkSpeedMultiplier = 6
|
||||||
|
Actions.CrouchSpeed = .2
|
||||||
|
--Flashlight static properties
|
||||||
|
Actions.FlashlightEnabled = false
|
||||||
|
|
||||||
|
local CharacterShared = _G.include(script, "CharacterShared")
|
||||||
|
local FlashlightRemote = CharacterShared:WaitForChild("Flashlight")
|
||||||
|
|
||||||
|
local Storage = game:GetService("ReplicatedStorage")
|
||||||
|
local RS = game:GetService("RunService")
|
||||||
|
|
||||||
|
local Tween = require(Storage:WaitForChild("Tween"))
|
||||||
|
local Delta = require(Storage:WaitForChild("Delta"))
|
||||||
|
|
||||||
|
type inherented = any
|
||||||
|
|
||||||
|
function Actions.constructor(HumanoidSettings: inherented, Humanoid: Humanoid, CurrentCamera: Camera)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
Humanoid = Humanoid,
|
Humanoid = Humanoid,
|
||||||
HumanoidSettingsInherent = HumanoidSettingsInherent
|
HumanoidSettings = HumanoidSettings,
|
||||||
|
CurrentCamera = CurrentCamera
|
||||||
}, Actions)
|
}, Actions)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actions:Enable()
|
function Actions:EnableSneak()
|
||||||
self.HumanoidSettingsInherent:SetWalkSpeed(Actions.Sneaking)
|
Actions.DoingAction = true
|
||||||
|
Actions.Sneaking = true
|
||||||
|
self.HumanoidSettings:SetWalkSpeed(Actions.SneakingSpeed)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actions:Disable()
|
function Actions:DisableSneak()
|
||||||
self.HumanoidSettingsInherent:SetWalkSpeed(Actions.Walk)
|
Actions.DoingAction = false
|
||||||
|
Actions.Sneaking = false
|
||||||
|
self.HumanoidSettings:SetWalkSpeed(Actions.Walk)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local CrouchTween = Tween.constructor()
|
||||||
|
|
||||||
|
function Actions:EnableCrouch(StandingWalkSpeed: number)
|
||||||
|
Actions.DoingAction = true
|
||||||
|
Actions.Crouching = true
|
||||||
|
|
||||||
|
local Easing = TweenInfo.new(Actions.CrouchSpeed, Enum.EasingStyle.Linear)
|
||||||
|
|
||||||
|
CrouchTween:Start(self.Humanoid, {
|
||||||
|
HipHeight = Actions.CrouchHeight,
|
||||||
|
WalkSpeed = math.max(1, StandingWalkSpeed-Actions.WalkSpeedMultiplier)
|
||||||
|
}, Easing)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actions:DisableCrouch(CrouchingWalkSpeed: number)
|
||||||
|
Actions.DoingAction = false
|
||||||
|
Actions.Crouching = false
|
||||||
|
|
||||||
|
local Easing = TweenInfo.new(Actions.CrouchSpeed, Enum.EasingStyle.Linear)
|
||||||
|
|
||||||
|
CrouchTween:Start(self.Humanoid, {
|
||||||
|
HipHeight = Actions.StandHeight,
|
||||||
|
WalkSpeed = math.max(1, CrouchingWalkSpeed+Actions.WalkSpeedMultiplier)
|
||||||
|
}, Easing)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actions:EnableFlashlight()
|
||||||
|
Actions.FlashlightEnabled = true
|
||||||
|
|
||||||
|
task.spawn(function()
|
||||||
|
while Actions.FlashlightEnabled do
|
||||||
|
|
||||||
|
Delta:time()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actions:DisableFlashlight()
|
||||||
|
Actions.FlashlightEnabled = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actions:EnableFlashlight()
|
||||||
|
if Actions.FlashlightEnabled then
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actions:ToggleCrouch()
|
||||||
|
if not Actions.DoingAction then
|
||||||
|
if Actions.Crouching then
|
||||||
|
self:DisableCrouch()
|
||||||
|
else
|
||||||
|
self:EnableCrouch()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Actions:ToggleSneak()
|
||||||
|
if not Actions.DoingAction then
|
||||||
|
if Actions.Sneaking then
|
||||||
|
self:DisableSneak()
|
||||||
|
else
|
||||||
|
self:EnableSneak()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
--!optimize 2
|
||||||
|
--!native
|
||||||
|
--!strict
|
||||||
|
|
||||||
local Bobbing = {}
|
local Bobbing = {}
|
||||||
Bobbing.__index = Bobbing
|
Bobbing.__index = Bobbing
|
||||||
|
|
||||||
@@ -84,8 +88,7 @@ local function CameraAnimation(self, dt: deltatime)
|
|||||||
|
|
||||||
--go go boolean algebra
|
--go go boolean algebra
|
||||||
local MaxMinY: boolean = Camera_YArc(self.CurrentCamera)>Bobbing.MaxGimbalLockY --TODO: instead, make this an equation so it will just subtract from the existing animation radians
|
local MaxMinY: boolean = Camera_YArc(self.CurrentCamera)>Bobbing.MaxGimbalLockY --TODO: instead, make this an equation so it will just subtract from the existing animation radians
|
||||||
local ForceStop: boolean = Bobbing.ForceStop and "Stop"
|
local AnimationType: string = Bobbing.ForceStop and "Stop" or RootMagnitude>1 and "Walk" or (not MaxMinY and "Idle" or "Stop")
|
||||||
local AnimationType: string = ForceStop or RootMagnitude>1 and "Walk" or (not MaxMinY and "Idle" or "Stop")
|
|
||||||
local CurrentAnimation: CFrame = Animations[AnimationType](Bobbing.Tick, dt)
|
local CurrentAnimation: CFrame = Animations[AnimationType](Bobbing.Tick, dt)
|
||||||
|
|
||||||
--"Lerp" so the transitions between walking and idling are smoothed instead of instant
|
--"Lerp" so the transitions between walking and idling are smoothed instead of instant
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
--!optimize 2
|
||||||
|
--!native
|
||||||
|
--!strict
|
||||||
|
|
||||||
local Camera = {}
|
local Camera = {}
|
||||||
local FakeCamera = {}
|
local FakeCamera = {}
|
||||||
Camera.__index = Camera
|
Camera.__index = Camera
|
||||||
@@ -35,7 +39,7 @@ function Camera:DisableBobbing()
|
|||||||
else
|
else
|
||||||
print("Character Camera: DisableBobbing was called before EnableBobbing", debug.traceback())
|
print("Character Camera: DisableBobbing was called before EnableBobbing", debug.traceback())
|
||||||
end
|
end
|
||||||
self.CurrentCamera.CFrame *= CFrame.Angles(0,0,0)
|
(self.CurrentCamera :: Camera).CFrame *= CFrame.Angles(0,0,0)
|
||||||
end
|
end
|
||||||
|
|
||||||
return Camera
|
return Camera
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
--!optimize 2
|
|
||||||
--!native
|
|
||||||
--!strict
|
|
||||||
|
|
||||||
local CrouchModule = {
|
|
||||||
IsCrouching = false,
|
|
||||||
StandHeight = 2.1,
|
|
||||||
CrouchHeight = .6,
|
|
||||||
WalkSpeedMultiplier = 6,
|
|
||||||
CrouchSpeed = .2
|
|
||||||
}
|
|
||||||
CrouchModule.__index = CrouchModule
|
|
||||||
|
|
||||||
local Tween = require(game:GetService("ReplicatedStorage"):WaitForChild("Tween"))
|
|
||||||
|
|
||||||
function CrouchModule.constructor(Humanoid: Humanoid)
|
|
||||||
return setmetatable({
|
|
||||||
Humanoid = Humanoid
|
|
||||||
}, CrouchModule)
|
|
||||||
end
|
|
||||||
|
|
||||||
local CrouchTween = Tween.constructor()
|
|
||||||
|
|
||||||
function CrouchModule:Crouch(StandingWalkSpeed: number)
|
|
||||||
local Easing = TweenInfo.new(CrouchModule.CrouchSpeed, Enum.EasingStyle.Linear)
|
|
||||||
|
|
||||||
CrouchTween:Start(self.Humanoid, {
|
|
||||||
HipHeight = CrouchModule.CrouchHeight,
|
|
||||||
WalkSpeed = math.max(1, StandingWalkSpeed-CrouchModule.WalkSpeedMultiplier)
|
|
||||||
}, Easing)
|
|
||||||
CrouchModule.IsCrouching = true
|
|
||||||
end
|
|
||||||
|
|
||||||
function CrouchModule:Stand(CrouchingWalkSpeed: number)
|
|
||||||
local Easing = TweenInfo.new(CrouchModule.CrouchSpeed, Enum.EasingStyle.Linear)
|
|
||||||
|
|
||||||
CrouchTween:Start(self.Humanoid, {
|
|
||||||
HipHeight = CrouchModule.StandHeight,
|
|
||||||
WalkSpeed = math.max(1, CrouchingWalkSpeed+CrouchModule.WalkSpeedMultiplier)
|
|
||||||
}, Easing)
|
|
||||||
CrouchModule.IsCrouching = false
|
|
||||||
end
|
|
||||||
|
|
||||||
return CrouchModule
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
--!optimize 2
|
|
||||||
--!native
|
|
||||||
--!strict
|
|
||||||
|
|
||||||
local Flashlight = {}
|
|
||||||
Flashlight.__index = Flashlight
|
|
||||||
|
|
||||||
local CharacterShared = _G.include(script, "CharacterShared")
|
|
||||||
local FlashlightRemote = CharacterShared:WaitForChild("Flashlight")
|
|
||||||
|
|
||||||
function Flashlight.constructor()
|
|
||||||
return setmetatable({}, Flashlight)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Flashlight:Toggle()
|
|
||||||
FlashlightRemote:FireServer()
|
|
||||||
end
|
|
||||||
|
|
||||||
return Flashlight
|
|
||||||
@@ -21,14 +21,13 @@ type struct_Spine = {
|
|||||||
Remote: UnreliableRemoteEvent,
|
Remote: UnreliableRemoteEvent,
|
||||||
CurrentCamera: CurrentCamera
|
CurrentCamera: CurrentCamera
|
||||||
}
|
}
|
||||||
|
|
||||||
type CharacterSharedFolder = Folder
|
type CharacterSharedFolder = Folder
|
||||||
|
|
||||||
function Spine.constructor(CurrentCamera: CurrentCamera)
|
function Spine.constructor(CurrentCamera: CurrentCamera)
|
||||||
local self = {} :: struct_Spine
|
return setmetatable({
|
||||||
self.Remote = CharacterShared:WaitForChild("SpineStream")
|
Remote = CharacterShared:WaitForChild("SpineStream"),
|
||||||
self.CurrentCamera = CurrentCamera
|
CurrentCamera = CurrentCamera
|
||||||
return setmetatable(self, Spine)
|
}, Spine)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Spine:Enable()
|
function Spine:Enable()
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ local HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart)
|
|||||||
local CameraConsturctor = CameraModule.constructor(CurrentCamera, HumanoidRootPart, Humanoid)
|
local CameraConsturctor = CameraModule.constructor(CurrentCamera, HumanoidRootPart, Humanoid)
|
||||||
local HumanoidSettings = HumanoidModule.constructor(Humanoid)
|
local HumanoidSettings = HumanoidModule.constructor(Humanoid)
|
||||||
local SpineMovement = SpineModule.constructor(CurrentCamera)
|
local SpineMovement = SpineModule.constructor(CurrentCamera)
|
||||||
local Flashlight = FlashlightModule.constructor()
|
|
||||||
|
|
||||||
local ClientBindMap = BindModule.constructor(false)
|
local ClientBindMap = BindModule.constructor(false)
|
||||||
|
|
||||||
@@ -106,3 +105,5 @@ SpineMovement:Enable()
|
|||||||
ClientCharacterBinds()
|
ClientCharacterBinds()
|
||||||
Crosshair3DVelocity_Effect()
|
Crosshair3DVelocity_Effect()
|
||||||
FlashlightToggle()
|
FlashlightToggle()
|
||||||
|
|
||||||
|
_G.include = nil
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
local Flashlight = {}
|
local Flashlight = {}
|
||||||
Flashlight.__index = Flashlight
|
Flashlight.__index = Flashlight
|
||||||
|
|
||||||
local Remote = Instance.new("RemoteEvent") :: RemoteEvent
|
local Remote = Instance.new("UnreliableRemoteEvent") :: UnreliableRemoteEvent
|
||||||
Remote.Name = "Flashlight"
|
Remote.Name = "Flashlight"
|
||||||
Remote.Parent = _G.include(script, "CharacterShared")
|
Remote.Parent = _G.include(script, "CharacterShared")
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ _G.include = function(this: LuaSourceContainer, FunName: string, ...)
|
|||||||
return type(switch) == "function" and switch(...) or switch
|
return type(switch) == "function" and switch(...) or switch
|
||||||
else
|
else
|
||||||
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
|
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user