Garry's Mod Wiki

Entity:PhysicsInit

  boolean Entity:PhysicsInit( number solidType, Vector massCenterOverride = nil )

Description

Initializes the physics object of the entity using its current model. Deletes the previous physics object if it existed and the new object creation was successful.

If the entity's current model has no physics mesh associated to it, no physics object will be created and the previous object will still exist, if applicable.

When called clientside, this will not create a valid PhysObj if the model hasn't been precached serverside.

If successful, this function will automatically call Entity:SetSolid( solidType ) and Entity:SetSolidFlags( 0 ).

Clientside physics objects are broken and do not move properly in some cases. Physics objects should only created on the server or you will experience incorrect physgun beam position, prediction issues, and other unexpected behavior.

A workaround is available on the Entity:PhysicsInitConvex page.

Issue Tracker: 5060

Arguments

1 number solidType
The solid type of the physics object to create, see SOLID enum. Should be SOLID_VPHYSICS in most cases.
Using SOLID_NONE will only delete the current physics object - it does not create a new one.
2 Vector massCenterOverride = nil
If set, overwrites the center of mass for the created physics object.
This was recently added in version (2024.10.29). It might only be available on the Dev Branch right now.

Returns

1 boolean
Returns true on success, false otherwise.