Skip to content

Commit

Permalink
Allow overriding physics init logic
Browse files Browse the repository at this point in the history
  • Loading branch information
StyledStrike committed Dec 30, 2024
1 parent 9fa6a01 commit e55f19f
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions lua/entities/base_glide/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,31 @@ function ENT:Initialize()

-- Setup the chassis model and physics
self:SetModel( self.ChassisModel )
self:SetSolid( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:PhysicsInit( SOLID_VPHYSICS )
self:InitializePhysics()
self:SetUseType( SIMPLE_USE )

local phys = self:GetPhysicsObject()

if not IsValid( phys ) then
self:Remove()
error( "Failed to setup physics! Vehicle removed!" )
return
end

phys:SetMaterial( "metalvehicle" )
phys:SetMass( self.ChassisMass )
phys:EnableDrag( false )
phys:SetDamping( 0, 0 )
phys:SetDragCoefficient( 0 )
phys:SetAngleDragCoefficient( 0 )
phys:SetBuoyancyRatio( 0.05 )
phys:EnableMotion( true )
phys:Wake()

self:StartMotionController()

debugoverlay.Cross( self:LocalToWorld( phys:GetMassCenter() ), 20, 5, Color( 0, 200, 0 ), true )

-- Let NPCs see through this vehicle
self:AddEFlags( EFL_DONTBLOCKLOS )
self:AddFlags( FL_OBJECT )
Expand All @@ -80,29 +100,6 @@ function ENT:Initialize()
-- Setup wheel systems
self:WheelInit()

local phys = self:GetPhysicsObject()

if IsValid( phys ) then
phys:SetMaterial( "metalvehicle" )
phys:SetMass( self.ChassisMass )
phys:EnableDrag( false )
phys:SetDamping( 0, 0 )
phys:SetDragCoefficient( 0 )
phys:SetAngleDragCoefficient( 0 )
phys:SetBuoyancyRatio( 0.05 )

phys:EnableMotion( true )
phys:Wake()

self:StartMotionController()

debugoverlay.Cross( self:LocalToWorld( phys:GetMassCenter() ), 20, 5, Color( 0, 200, 0 ), true )
else
self:Remove()
error( "Failed to setup physics! Vehicle removed!" )
return
end

local data = { Color = self:GetSpawnColor() }

self:SetColor( data.Color )
Expand Down Expand Up @@ -147,6 +144,12 @@ function ENT:Initialize()
self:CreateFeatures()
end

function ENT:InitializePhysics()
self:SetSolid( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:PhysicsInit( SOLID_VPHYSICS )
end

function ENT:OnRemove()
-- Stop physics processing
local phys = self:GetPhysicsObject()
Expand Down

0 comments on commit e55f19f

Please sign in to comment.