AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') constrained = false function ENT:Initialize() self.Entity:SetModel('models/props_c17/oildrum001.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() phys:EnableGravity(false) end self:MakeUpright(self.Entity, Angle(0,0,0), 0, 100000) self.Entity:SetMaterial("models/shiny") end function ENT:Think() local trace={} trace.startpos=self.Entity:GetPhysicsObject():GetPos() trace.endpos=self.Entity:GetPhysicsObject():GetPos() - Vector(0,0,10000) trace.ignore = self.Entity local traceRes=util.TraceLine(trace) local force = -50 * (trace.startpos.z - (traceRes.HitPos.z + 50)) self.Entity:GetPhysicsObject():ApplyForceCenter(Vector(0,0,force)) force = -0.3*self.Entity:GetVelocity().z*self.Entity:GetPhysicsObject():GetMass() self.Entity:GetPhysicsObject():ApplyForceCenter(Vector(0,0,force)) end function ENT:MakeUpright(Entity, Ang, Bone, angularlimit) local Phys = Entity:GetPhysicsObjectNum(Bone) local constraint = ents.Create( "phys_keepupright" ) constraint:SetAngles( Ang ) constraint:SetKeyValue( "angularlimit", angularlimit ) constraint:SetPhysConstraintObjects( Phys, Phys ) constraint:Spawn() constraint:Activate() end