Continuous upwards force on an entity

Im trying to make a prop that will pull upwards with a certain amount of force. It will eventually be for making airships. My problem right now is that it will shoot up for about a second when it spawns, and then fall back and just sit there. The wiki says that phys.SetVelocity is supposed to be infinite. Here’s my init.lua:



AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

function ENT:Initialize()

	self.Entity:SetModel( "models/props_wasteland/cargo_container01.mdl" )
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )

   local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
	end
	phys:SetMass( 1000 )
	phys:SetVelocity(Vector(0,0,5000))
	
end


[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

function ENT:Initialize()
self.Entity:SetModel( “models/props_wasteland/cargo_container01.mdl” )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )

local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
	phys:Wake()
end
phys:SetMass( 1000 )
hook.Add("Tick" , self:EntIndex().."PushUp" , function()
	phys:ApplyForceOffset(Vector(0, 0, 30), Vector(0, 0, 0) )
end )

end [/lua]

Try that.

The problem is you were only setting the velocity once - which will mean that it will fall back down to earth. If you constantly apply a force (Could use the limit formula to find out the perfect force to keep it hovering) then it will stay in the air.

The tick hook is called on each server tick - which is normally 66 or 100 times per second.

When I copy-pasted that, it made it roll forever. So, partial success. I figured you just put the force in the wrong place, but when I tried to fix it, it didn’t work at all.

You just need to apply more upward force for such a big thing.

You could use phys:SetVelocity rather than phys:ApplyForceOffset.

I just used it because it gives a more realistic result :3

More force than 5000? I guess I’ll try it, but I doubt that’s my problem.

Why the unnecessary hooks, sir?

[lua]AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include(‘shared.lua’)

function ENT:Initialize()
self.Entity:SetModel( “models/props_wasteland/cargo_container01.mdl” )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )

local phys = self.Entity:GetPhysicsObject()  
if (phys:IsValid()) then  
    phys:Wake()  
end  
phys:SetMass( 1000 )  

end

local function ForceUp()
for k, v in pairs (ents.FindByClass(ENT_CLASS_NAME_HERE)) do
local phys = v:GetPhysicsObject()
if phys:IsValid() then
phys:ApplyForceCenter(Vector(0, 0, 1000) )
end
end
end

hook.Add(“Tick”, “ENT_CLASS_NAME_HERE_PushUp”, ForceUp)

[/lua]

Have you tried PhysObj.ComputeShadowControl? It’s really good at controlling movement and make things hover smoothly. Don’t let the function scare you it’s actually really easy to use. :smile:

Problem with the OP’s code snippet is that you’re putting the velocity in initialize. It sets the velocity upwards once, and leaves it free to accelerate how it likes after that. It was effectively just launched up in the air like from a giant spring.

You need to put the code for setting velocity or applying force in think, which runs 10 times a second by default, if you want the force to be constant.

Think runs every frame.

Is also useful.

Funny that I got rated late even though no one has posted this.

This actually looks like the best option. If the OP is still checking in on this thread, I’d use this. Put a line in it like phys:SetVelocity(0,0,1000) or something.

That’s exactly what I suggested. :frown:

But yeah definitely the best place in which to mess with an entity’s physics.

physics update works. I’m tweaking the settings now, but I have proof of concept. Thanks all.

-snip-

Number is wrong, didn’t include deltatime.

What seriously? Is that some sort of gravitational constant equivalent in the Source Engine?

For a 600 in/sec gravity, yeah. Don’t ask me why that’s what it is, I haven’t the slightest clue. it isn’t F=ma, for some odd reason.

Objects in source don’t fall at a uniform rate.

I’m not sure if it’s highly exacerbated air friction or just force based on mass.

Constant is ( sv_gravity:GetInt( ) / 600 ) * ( sv_gravity:GetInt( ) / -16 )

Or -37.5.

That’s the gravity constant method I use to calculate the needed angle for object x to travel y distance that weighs z.

Works like a charm, too, so I think that number mentioned is just a lucky magic number.

Whoa, sorry, I completely forgot about my deltatime. My number is off, sorry. Although where did you get your -16 from?

I was just applying that number (about 9) times weight in an object’s PhysicsUpdate to get weightlessness. Drag is off, and model doesn’t matter.