Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local WaterDict = game.Workspace.WaterFolder:GetChildren()
- local Torso = script.Parent:WaitForChild("Torso")
- local ShouldUpdateMass = true
- local Mass = 0
- local WorldGravity = 196.2
- local WaterGravity = WorldGravity / 4
- local GravityForce = Instance.new("BodyForce", Torso)
- local UnderWaterEffect = game:GetService("Lighting"):WaitForChild("UnderWaterEffect")
- local UnderWaterSwampEffect = game:GetService("Lighting"):WaitForChild("UnderWaterSwampEffect")
- local UnderLavaEffect = game:GetService("Lighting"):WaitForChild("UnderLavaEffect")
- local UnderWaterSoundEffects = {}
- for _, Effect in pairs(game:GetService("SoundService"):WaitForChild("Music"):GetChildren()) do
- if Effect.Name == "UnderWaterEffect" then
- table.insert(UnderWaterSoundEffects, Effect)
- end
- end
- local Camera = game:GetService("Workspace").CurrentCamera
- function GetCharacterMass()
- local CharacterMass = 0
- for _, Inst in pairs(script.Parent:GetDescendants()) do
- if Inst:IsA("BasePart") then
- CharacterMass = CharacterMass + Inst:GetMass()
- end
- end
- return CharacterMass
- end
- function IsUnderWater(X, Y, Z)
- if Y <= 17.5 and Y >= -43 then return true, "Normal" end -- ocean btw
- for _, i in pairs(WaterDict) do
- if X>i.Position.X-(i.Size.X/2) and X<i.Position.X+(i.Size.X/2) and Y>i.Position.Y-(i.Size.Y/2) and Y<i.Position.Y+(i.Size.Y/2) and Z>i.Position.Z-(i.Size.Z/2) and Z<i.Position.Z+(i.Size.Z/2) then
- return true, i.Biome.Value
- end
- end
- return false, "None"
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- if ShouldUpdateMass then Mass = GetCharacterMass() end
- local UnderWater, WaterType = IsUnderWater(Torso.Position.X, Torso.Position.Y, Torso.Position.Z)
- GravityForce.Force = Vector3.new(0, UnderWater and ((Mass * WorldGravity) - (Mass * WaterGravity)) or 0, 0)
- for _, Effect in pairs(UnderWaterSoundEffects) do
- Effect.Enabled = UnderWater
- end
- end)
- game:GetService("RunService").RenderStepped:Connect(function()
- local UnderWater, WaterType = IsUnderWater(Camera.CFrame.X, Camera.CFrame.Y, Camera.CFrame.Z)
- UnderLavaEffect.Enabled = UnderWater and WaterType == "Lava"
- UnderWaterEffect.Enabled = UnderWater and WaterType == "Normal"
- UnderWaterSwampEffect.Enabled = UnderWater and WaterType == "Swamp"
- end)
- script.Parent.DescendantAdded:Connect(function() ShouldUpdateMass = true end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement