Correct calculation to negate gravity

Hoy there.

Using ApplyForceCenter() under ENT:Think(), I’m trying to create a TTT weapon that negates gravity. Essentially, the code loops ( for a, b in pairs) through a table that finds the prop in its radius, and apply force to them to negate gravity. Problem is that I can’t seem to get the correct amount of force; it’s either too much, or too little.

For example, I have tried:




phys:ApplyForceCenter(Vector(0,0,9.8) * phys:GetMass()) 



This doesn’t seem to do anything.




phys:ApplyForceCenter(-Vector(0,0,mass) * physenv.GetGravity())



This one cause too much force, and everything slams into the ceiling.

I’m not sure whats too wrong - could be the dodgy mass of objects in the map I’m testing on, or perhaps the tick rates, though I don’t know much about them.

If anyone could help here, I would appreciate it.

Cheers for reading, thanks in advance.

sv_gravity’s convar value * ent:GetGravity() ?

Thanks for replying. I gave it a whirl


 p:ApplyForceCenter(Vector(0,0,physenv.GetGravity() * d:GetGravity())) 

Again, the first snippet i showed you, it appears to have no effect on the objects. Have I entered it correctly? Thanks again.

Hm. You could try applying a force offset as a negative of the Z velocity.

Never used force offset, how would I use it?

p:ApplyForceCenter(Vector(0,0,p:GetVelocity().z*-1))

I did some tweaking of that and managed to get it working pretty well, albeit a bit crude-looking. Thanks a bunch.