Disabling Player gravity in a brush volume

I’m trying to make a brush entity which disables gravity for all objects that come into it. I’ve been using physobj:IsGravityEnabled() for physics objects, but players and ragdolls are unaffected by it. So, I decided to try and make a special case for that, simply adding velocity to any players in the brush to counteract gravity. The results are less then satisfactory.

I made a table of players which adds players on StartTouch and removes them on EndTouch. Then, I made a think function that runs every server tick, and adds a velocity to each player in the list that I tweaked to more or less disable gravity. However, its’ not quite as effective as I thought it would be.

This is what the think function looks like:


function ENT:Think()
	upVector = Angle(0, 0, 0):Up() --get the "Up" direction
	for k, v in pairs(self:GetVar("players",{})) do --loop through all players in volume (table is defined and filled up elsewhere)
		v:SetVelocity(upVector * 19.205) --added upward velocity to players (abstract value roughly counters gravity)
	end

	--This ensures that the code runs every server tick
	self:NextThink( CurTime() )
	return true
end

The problem is that it doesn’t always apply the anti-gravity at consistent times; sometimes it pushes the player too often and starts weakly launching them upwards, and sometimes it applies it too sparingly and allows them to start falling. Is there a better way to do this?

I haven’t been able to get that to work. In fact, my brush entity has been setting that since I first started, I’ve had to find completely different ways to get things working. It’s still in the code, but since it doesn’t do anything, I’ve had to find other ways to do it. Example:


function ENT:StartTouch( ent )
	ent:SetGravity(0)
	physobj = ent:GetPhysicsObject()
	
	if(physobj:IsValid() and self:GetVar("enabled",true)) then
		print("gravity disabled")
		physobj:EnableGravity(false)
		print(physobj:IsGravityEnabled())
	end
	print("starttouch")
end

Disabling the code dealing with physobj:IsGravityEnabled() will show that SetGravity doesn’t do anything. I’ve tried setting it to non-zero values like 0.001 (which works with func_gravity), but it does nothing here.

Also, I know func_gravity is a thing, but that only works on players, and my brush is ultimately going to do more things anyways.