diff --git a/src/client/Character/Server/init.server.lua b/src/client/Character/Server/init.server.lua index 9914acd..e1c4650 100644 --- a/src/client/Character/Server/init.server.lua +++ b/src/client/Character/Server/init.server.lua @@ -1,6 +1,6 @@ local Character = script.Parent -local Shadows = require(script:WaitForChild("Shadows")) +local Shadows = require(script:WaitForChild("Shadows")) local HumanoidModule = require(script:WaitForChild("Humanoid")) local Humanoid = Character:WaitForChild("Humanoid") diff --git a/src/client/Player/Camera/Bobbing.lua b/src/client/Player/Camera/Bobbing.lua new file mode 100644 index 0000000..c4dda9d --- /dev/null +++ b/src/client/Player/Camera/Bobbing.lua @@ -0,0 +1,3 @@ +return function(dt) + +end \ No newline at end of file diff --git a/src/client/Player/Camera/init.lua b/src/client/Player/Camera/init.lua index d1229ef..a165271 100644 --- a/src/client/Player/Camera/init.lua +++ b/src/client/Player/Camera/init.lua @@ -1,13 +1,26 @@ -local Camera = { - FOV = { - Default = 70, - Zoomed = 50 - } -} +local Camera = {} Camera.__index = Camera -function Camera.constructor(Player: Player) +Camera.FOV = { + Default = 70, + Zoomed = 40, +} +Camera.FOV.Speed = { + In = 0.3, + Out = 0.4 +} + +local Storage = game:GetService("ReplicatedStorage") +local RS = game:GetService("RunService") + +local Tween = require(Storage:WaitForChild("Tween")) +-- local Bobbing = require(script:WaitForChild("Bobbing")) + +local ZoomTween = Tween.constructor() + +function Camera.constructor(CurrentCamera: Camera, Player: Player) return setmetatable({ + Camera = CurrentCamera, Player = Player }, Camera) end @@ -16,4 +29,28 @@ function Camera:LockFirstPerson() self.Player.CameraMode = Enum.CameraMode.LockFirstPerson end +function Camera:EnableBobbing() + self.CameraFrames = RS.RenderStepped:Connect(function(dt) + + end) +end + +function Camera:DisableBobbing() + if self.CameraFrames then + self.CameraFrames:Disconnect() + end +end + +function Camera:ZoomIn() + ZoomTween:Start(self.Camera, { + FieldOfView = Camera.FOV.Zoomed + }, TweenInfo.new(Camera.FOV.Speed.In, Enum.EasingStyle.Quad)) +end + +function Camera:ZoomOut() + ZoomTween:Start(self.Camera, { + FieldOfView = Camera.FOV.Default + }, TweenInfo.new(Camera.FOV.Speed.Out, Enum.EasingStyle.Quad)) +end + return Camera \ No newline at end of file diff --git a/src/client/Player/init.client.lua b/src/client/Player/init.client.lua index b7960bd..7689e90 100644 --- a/src/client/Player/init.client.lua +++ b/src/client/Player/init.client.lua @@ -4,12 +4,36 @@ local CameraSettings = require(script:WaitForChild("Camera")) local Crosshair = require(script:WaitForChild("Crosshair")) local Players = game:GetService("Players") -local Player = Players.LocalPlayer +local Storage = game:GetService("ReplicatedStorage") -local Camera = CameraSettings.constructor(Player) +local ClientStorage = Storage:WaitForChild("Client") +local KeyBindsModule = require(ClientStorage:WaitForChild("KeyBinds")) + +local Player = Players.LocalPlayer +local CurrentCamera +repeat + task.wait() + CurrentCamera = workspace.CurrentCamera +until CurrentCamera + +local Camera = CameraSettings.constructor(CurrentCamera, Player) local CrosshairObject = Crosshair.constructor(Player) +--Keybinds +local function CameraBinds() + local CameraBindMap = KeyBindsModule.constructor() + + CameraBindMap:AddInputBegan(Enum.KeyCode.C, function() + Camera:ZoomIn() + end) + CameraBindMap:AddInputEnded(Enum.KeyCode.C, function() + Camera:ZoomOut() + end) +end + CoreGuis:off() Mouse:DisablePointer() Camera:LockFirstPerson() -CrosshairObject:Spawn() \ No newline at end of file +CrosshairObject:Spawn() + +CameraBinds() \ No newline at end of file diff --git a/src/shared/Client/KeyBinds.lua b/src/shared/Client/KeyBinds.lua index f01a8db..c86870a 100644 --- a/src/shared/Client/KeyBinds.lua +++ b/src/shared/Client/KeyBinds.lua @@ -1,7 +1,5 @@ -local Binds = {} -local BindsMap = {} -Binds.__index = Binds -BindsMap.__index = BindsMap +local BindLink = {} +BindLink.__index = BindLink local UIS = game:GetService("UserInputService") @@ -10,57 +8,64 @@ export type KeyBindMap = { [Enum.KeyCode]: () -> () } } - -function Binds.constructor() --Allow multiple bindings of the same keys, no overwrites - local RegisteredKeys: KeyBindMap = { - Began = {}, - Ended = {} - } - return setmetatable({ - RegisteredKeys = RegisteredKeys - }, BindsMap) -end +export type InputBegan = RBXScriptConnection +export type InputEnded = RBXScriptConnection type CallbackFunction = () -> () -function Binds:Add(Key: Enum.KeyCode, Callback: CallbackFunction) - local k = self.RegisteredKeys[Key] - if k then - warn(`Key "{Key.Name}" is already binded on this KeyBind map`) +function BindLink.constructor() --Allow multiple bindings of the same keys, no overwrites + type BindConstructor = { + BindMap: KeyBindMap, + InputBegan: InputBegan, + InputEnded: InputEnded + } + + local self: BindConstructor = {} + self.BindMap = { + Began = {}, + Ended = {} + } + --Return these for convenience + self.InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent) + if not gameProcessedEvent then + local switch = self.BindMap.Began[input.KeyCode] + if switch then + switch() + else + --switch.default() + end + end + end) + self.InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent) + if not gameProcessedEvent then + local switch = self.BindMap.Ended[input.KeyCode] + if switch then + switch() + else + --switch.default() + end + end + end) + + return setmetatable(self, BindLink) +end + +function BindLink:AddInputBegan(Key: Enum.KeyCode, Callback: CallbackFunction) + if self.BindMap.Began[Key] then + warn(`Key >began< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback()) end - self.RegisteredKeys[Key] = Callback + self.BindMap.Began[Key] = Callback end -function BindsMap.NewBindState(RegisteredKeys: KeyBindMap) - local InputBegan = UIS.InputBegan:Connect(function(input, gameProcessedEvent) - if not gameProcessedEvent then - local switch = RegisteredKeys.Began[input.KeyCode] - if switch then - switch() - else - --switch.default() - end - end - end) - - local InputEnded = UIS.InputEnded:Connect(function(input, gameProcessedEvent) - if not gameProcessedEvent then - local switch = RegisteredKeys.Ended[input.KeyCode] - if switch then - switch() - else - --switch.default() - end - end - end) - - return setmetatable({ - --Return these for convenience - InputBegan = InputBegan, - InputEnded = InputEnded - }, BindsMap) +function BindLink:AddInputEnded(Key: Enum.KeyCode, Callback: CallbackFunction) + if self.BindMap.Ended[Key] then + warn(`Key >ended< "{Key.Name}" is already binded on this KeyBind map`, debug.traceback()) + end + self.BindMap.Ended[Key] = Callback end +function BindLink:KeyHold(Key: Enum.KeyCode): boolean + return UIS:IsKeyDown(Key) +end - -return Binds \ No newline at end of file +return BindLink \ No newline at end of file diff --git a/src/shared/Tween.lua b/src/shared/Tween.lua index 8777ffd..573c011 100644 --- a/src/shared/Tween.lua +++ b/src/shared/Tween.lua @@ -5,11 +5,7 @@ local TS = game:GetService("TweenService") type TweenAnimation = {[string]: any} -function Tween.constructor( - TweenSettings: TweenInfo, - Object: Instance | nil, - PreProperties: TweenAnimation | nil -) +function Tween.constructor(TweenSettings: TweenInfo | nil, Object: Instance | nil, PreProperties: TweenAnimation | nil) return setmetatable({ TweenInfo = TweenSettings, Instance = Object, @@ -17,30 +13,30 @@ function Tween.constructor( }, Tween) end -function Tween:Start( - PostInstance: Instance | nil, - PostProperties: TweenAnimation | nil, - PostTweenSettings: TweenInfo | nil -): Tween +function Tween:Start(PostInstance: Instance | nil, PostProperties: TweenAnimation | nil, PostTweenSettings: TweenInfo | nil): Tween local Props = self.PreProperties local Object = self.Instance local TweenSettings = self.TweenInfo - if PostProperties and self.PreProperties then - for tween_prop, tween_value in PostProperties do - Props[tween_prop] = tween_value + if PostProperties then + if self.PreProperties then + for tween_prop, tween_value in PostProperties do + Props[tween_prop] = tween_value + end + print("Tween library: Combining PostProperties and PreProperties together", debug.traceback()) + else + Props = PostProperties end - print("Tween library: Combining PostProperties and PreProperties") end if PostInstance then if Object then - print("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance) + print("Tween library: Overwriting an already defined animating object old=", Object, "new=", PostInstance, debug.traceback()) end Object = PostInstance end if PostTweenSettings then if TweenSettings then - print("Tween library: Overwriting already defined Tween settings") + print("Tween library: Overwriting already defined Tween settings", debug.traceback()) end TweenSettings = PostTweenSettings end