Hi,
I made a camera class with land shake and everything is working well but when I reset, for some reason the vertical velocity of the player repeats 0. I have no idea why this is happening.
--!strict
--/ services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--/ directories
local Source = ReplicatedStorage.Source
local Modules = Source.Dependencies
local Classes = Source.Classes
local Packages = ReplicatedStorage.Packages
--/ requires
local Trove = require(Packages._Index["sleitnick_trove@1.1.0"]["trove"])
local CameraShaker = require(Modules.CameraShaker)
local CameraShakeInstance = require(Modules.CameraShaker.CameraShakeInstance)
--/ variables
local CurrentCamera = workspace.CurrentCamera
--/ class
local Camera = {}
Camera.__index = Camera
export type ClassType = typeof( setmetatable({} :: {
Connections: Trove.ClassType,
character: any,
}, Camera) )
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
CurrentCamera.CFrame = CurrentCamera.CFrame * shakeCf
end)
function Camera.new(): ClassType
local self = {
Connections = Trove.new(),
character = nil,
};
setmetatable(self, Camera)
self:_init()
return self
end
--/ private methods
function Camera._init(self: ClassType): () -- initilize
Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
camShake:Start()
self:_setupCharacterAddedFunction()
end
function Camera._setupCharacterAddedFunction(self: ClassType)
self.Connections:Connect(Players.LocalPlayer.CharacterAdded, function(character: Model)
if not self.character then
self.character = character
end
end)
if Players.LocalPlayer then
if not self.character then
self.character = Players.LocalPlayer.Character:: Model
end
end
end
--/ update the camera (runservice)
function Camera.Update(self: ClassType, deltaTime: number): ()
if self.character then
local Root = self.character:FindFirstChild("HumanoidRootPart") :: BasePart
local Humanoid = self.character:FindFirstChild("Humanoid") :: Humanoid
local MouseDelta = UserInputService:GetMouseDelta()
local VerticalSpeed = math.abs(Root.AssemblyLinearVelocity.Y)
-- Land shake:
local isGrounded = if Humanoid:GetState() == Enum.HumanoidStateType.Landed
then true else false
print(VerticalSpeed)
if VerticalSpeed > 65 and isGrounded then
camShake:ShakeOnce(1.5, 3.5, 0.1, 0.575)
end
end
end
function Camera.Enable(self: ClassType): ()
local function _update(deltaTime)
self:Update(deltaTime)
end
self.Connections:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value + 1, _update)
end
function Camera.Disable(self: ClassType): ()
self.Connections:Clean()
end
return Camera
After I reset, the vertical speed / assemblylinearvelocity.y prints this:
0 (x569)