Disabling gravity for players

I have a bunch of blocks that players need to be able to work on. The problem is that those blocks only exist in Lua and not in the physics engine (and for certain reasons this is not an option.) For this reason I want to be able to disable and enable the gravity manually. Relying on sv_gravity 0 to do the job doesn’t really seem like a good idea, so I want to do it with Lua.

Currently I have the following code:

[lua]function GM:Think()
for _, ply in ipairs( player.GetAll() ) do
local vel, pos = ply:GetVelocity(), ply:GetPos()

	ply:SetVelocity( Vector( -vel.x, -vel.y, -vel.z ) )
	
	pos.z = 512.1
	ply:SetPos( pos )
end

end[/lua]

That produces the following result:

As you can see it looks a bit laggy and SetPos really isn’t the ideal solution. Does anyone know what the force is I need to apply to completely cancel the effect of gravity?

First of all, is it shared?

No it isn’t, but that isn’t the problem here. If I stand above the hole for a while, I slowly fall in it.

player:SetGravity(1)
player:SetGravity(0)

or maybe SetMoveType(MOVETYPE_FLY)?

Nevermind, I’ve found a much better way to solve my problem. Thanks anyway. knarf, SetGravity didn’t work.

I’m a little curious if you wouldn’t mind sharing?

Well, solving my problem without disabling gravity.

And the solution was…

Using temporary physics objects to simulate ground where necessary.

Make sure it’s shared so it’s predicted.