Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable GravityController while Seated #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/StarterPack/GravityControl/tool.client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ params.FilterDescendantsInstances = {}
params.FilterType = Enum.RaycastFilterType.Blacklist

local gravityController = nil
local player = Players.LocalPlayer
local isEquipped = false
local isSeated = false

local function getGravityUp(self, oldGravity)
local result = workspace:Raycast(self.HRP.Position, -5*oldGravity, params)
Expand All @@ -19,8 +22,8 @@ local function getGravityUp(self, oldGravity)
return oldGravity
end

tool.Equipped:Connect(function()
gravityController = GravityControllerClass.new(Players.LocalPlayer)
local function enableGravityController()
gravityController = GravityControllerClass.new(player)
gravityController.GetGravityUp = getGravityUp
gravityController.Maid:Mark(RunService.Heartbeat:Connect(function(dt)
local height = gravityController:GetFallHeight()
Expand All @@ -30,10 +33,33 @@ tool.Equipped:Connect(function()
end))

params.FilterDescendantsInstances = {gravityController.Character}
end)
end

tool.Unequipped:Connect(function()
local function disableGravityController()
if gravityController then
gravityController:Destroy()
end
end)
end

tool.Equipped:Connect(function()
isEquipped = true
if (not isSeated) then
enableGravityController()
end
end)
tool.Unequipped:Connect(function()
isEquipped = false
disableGravityController()
end)

local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")

Humanoid.Seated:Connect(function(seated)
isSeated = seated
if seated then
disableGravityController()
elseif isEquipped then
enableGravityController()
end
end)