From ecbbc5971a06065b29fd0202d7b988f4e897ebc0 Mon Sep 17 00:00:00 2001 From: interpreterK Date: Wed, 27 Dec 2023 14:02:20 -0500 Subject: [PATCH] crouching and move Humanoid.lua from server to client --- src/client/Character/Client/Crouch.lua | 31 +++++++++++++++++++ .../Character/{Server => Client}/Humanoid.lua | 0 src/client/Character/Client/init.client.lua | 24 +++++++++++++- src/client/Character/Server/init.server.lua | 7 +---- 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/client/Character/Client/Crouch.lua rename src/client/Character/{Server => Client}/Humanoid.lua (100%) diff --git a/src/client/Character/Client/Crouch.lua b/src/client/Character/Client/Crouch.lua new file mode 100644 index 0000000..779a4fb --- /dev/null +++ b/src/client/Character/Client/Crouch.lua @@ -0,0 +1,31 @@ +local CrouchModule = { + StandHeight = 2.1, + CrouchHeight = .6 +} +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) + CrouchTween:Start(self.Humanoid, { + HipHeight = CrouchModule.CrouchHeight, + WalkSpeed = StandingWalkSpeed-6 + }, TweenInfo.new(.4)) +end + +function CrouchModule:Stand(CrouchingWalkSpeed: number) + CrouchTween:Start(self.Humanoid, { + HipHeight = CrouchModule.StandHeight, + WalkSpeed = CrouchingWalkSpeed+6 + }, TweenInfo.new(.2)) +end + +return CrouchModule \ No newline at end of file diff --git a/src/client/Character/Server/Humanoid.lua b/src/client/Character/Client/Humanoid.lua similarity index 100% rename from src/client/Character/Server/Humanoid.lua rename to src/client/Character/Client/Humanoid.lua diff --git a/src/client/Character/Client/init.client.lua b/src/client/Character/Client/init.client.lua index c317275..e39f917 100644 --- a/src/client/Character/Client/init.client.lua +++ b/src/client/Character/Client/init.client.lua @@ -1,5 +1,11 @@ +local Storage = game:GetService("ReplicatedStorage") +local ClientStorage = Storage:WaitForChild("Client") + local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart")) local CameraModule = require(script:WaitForChild("Camera")) +local CrouchModule = require(script:WaitForChild("Crouch")) +local BindModule = require(ClientStorage:WaitForChild("KeyBinds")) +local HumanoidModule = require(script:WaitForChild("Humanoid")) local Character = script.Parent local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") @@ -8,6 +14,22 @@ local CurrentCamera = workspace.CurrentCamera local HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart) local CameraConsturctor = CameraModule.constructor(CurrentCamera, HumanoidRootPart, Humanoid) +local HumanoidSettings = HumanoidModule.constructor(Humanoid) +local function CrouchFeature() + local CrouchConstructor = CrouchModule.constructor(Humanoid) + local CourchBindMap = BindModule.constructor() + + CourchBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function() + CrouchConstructor:Crouch(10) + end) + CourchBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function() + CrouchConstructor:Stand(5) + end) +end + +HumanoidSettings:SetWalkSpeed(10) HRPSettings:DisableRobloxSounds() -CameraConsturctor:EnableBobbing() \ No newline at end of file +CameraConsturctor:EnableBobbing() + +CrouchFeature() \ No newline at end of file diff --git a/src/client/Character/Server/init.server.lua b/src/client/Character/Server/init.server.lua index 64bd775..d739931 100644 --- a/src/client/Character/Server/init.server.lua +++ b/src/client/Character/Server/init.server.lua @@ -1,15 +1,10 @@ local Character = script.Parent -local Shadows = require(script:WaitForChild("Shadows")) -local HumanoidModule = require(script:WaitForChild("Humanoid")) - -local Humanoid = Character:WaitForChild("Humanoid") +local Shadows = require(script:WaitForChild("Shadows")) local CharacterShadows = Shadows.constructor(Character) -local HumanoidSettings = HumanoidModule.constructor(Humanoid) CharacterShadows:off() --I plan to have 2 player support and characters block a ton of light -HumanoidSettings:SetWalkSpeed(10) Character.DescendantAdded:Connect(function(Instance) task.wait() --Wait for the instance to properly replicate?