Camera zoom keybind and starting camera bobbing animations

This commit is contained in:
2023-12-20 17:44:46 -05:00
parent bfca13ed6e
commit b879e5ac85
6 changed files with 141 additions and 76 deletions

View File

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

View File

@@ -0,0 +1,3 @@
return function(dt)
end

View File

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

View File

@@ -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()
CrosshairObject:Spawn()
CameraBinds()