Part/Model Gravity Adjuster Based on Height

A script that changes local gravity based on height (configurable)

Simple but useful ^^
https://gyazo.com/ab1c5c4bbe33ca71e33ce008ac26f8b5

Script
while wait() do
	if script.Parent:IsA("BasePart") then -- Checking if the script's Parent needs to get a gravity edit
		local F = script.Parent:FindFirstChild("AccurateGravity")
		if not F then
			F = Instance.new("BodyForce")
			F.Name = "AccurateGravity"
			F.Archivable = false
			F.Parent = script.Parent
		end
		local H = script.Parent.Position.Y/script.ZeroGHeight.Value
		local G = math.clamp(workspace.Gravity * H, 0, workspace.Gravity)
		F.Force = script.Parent.Velocity + Vector3.new(0,script.Parent:GetMass() * G,0)
		--print("Height: ".. tostring(script.Parent.Position.Y))
		--print("Velocity: ".. tostring(script.Parent.Velocity))
		--print("Current Gravity: ".. workspace.Gravity-G)
	end
	
	for I,V in pairs(script.Parent:GetChildren()) do -- Checking if the script's Parent has children that need to get a gravity edit
		if V:IsA("BasePart") then
			local F = V:FindFirstChild("AccurateGravity")
			if not F then
				F = Instance.new("BodyForce")
				F.Name = "AccurateGravity"
				F.Archivable = false
				F.Parent = V
			end
			local H = V.Position.Y/script.ZeroGHeight.Value
			local G = math.clamp(workspace.Gravity * H, 0, workspace.Gravity)
			F.Force = Vector3.new(0,V:GetMass() * G,0)
			--print("Height: ".. tostring(V.Position.Y))
			--print("Velocity: ".. tostring(V.Velocity))
			--print("Current Gravity: ".. workspace.Gravity-G)
		end
	end
end
12 Likes