crouching and move Humanoid.lua from server to client

This commit is contained in:
2023-12-27 14:02:20 -05:00
parent d46b4dc844
commit ecbbc5971a
4 changed files with 55 additions and 7 deletions

View File

@@ -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

View File

@@ -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()
CrouchFeature()

View File

@@ -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 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?