Garry's Mod Wiki

PhysObj

This is the object returned by Entity:GetPhysicsObject, Entity:GetPhysicsObjectNum and Vehicle:GetWheel.

It represents a physics object.

Methods

PhysObj:AddAngleVelocity( Vector angularVelocity )
Adds the specified angular velocity velocity to the current PhysObj.
PhysObj:AddGameFlag( number flags )
Adds one or more bit flags.
PhysObj:AddVelocity( Vector velocity )
Adds the specified velocity to the current.
Angle PhysObj:AlignAngles( Angle from, Angle to )
Rotates the object so that it's angles are aligned to the ones inputted.
PhysObj:ApplyForceCenter( Vector impulse )
Applies the specified impulse in the mass center of the physics object. This will not work on players, use Entity:SetVelocity instead.
PhysObj:ApplyForceOffset( Vector impulse, Vector position )
Applies the specified impulse on the physics object at the specified position.
PhysObj:ApplyTorqueCenter( Vector angularImpulse )
Applies the specified angular impulse to the physics object. See PhysObj:CalculateForceOffset
Vector, Vector PhysObj:CalculateForceOffset( Vector impulse, Vector position )
Calculates the linear and angular impulse on the object's center of mass for an offset impulse. The outputs can be used with PhysObj:ApplyForceCenter and PhysObj:ApplyTorqueCenter, respectively. Be careful to convert the angular impulse to world frame (PhysObj:LocalToWorldVector) if you are going to use it with ApplyTorqueCenter.
Vector, Vector PhysObj:CalculateVelocityOffset( Vector impulse, Vector position )
Calculates the linear and angular velocities on the center of mass for an offset impulse. The outputs can be directly passed to PhysObj:AddVelocity and PhysObj:AddAngleVelocity, respectively. This will return zero length vectors if the physics object's motion is disabled. See PhysObj:IsMotionEnabled.
PhysObj:ClearGameFlag( number flags )
Removes one of more specified flags.
PhysObj:ComputeShadowControl( table shadowparams )
Allows you to move a PhysObj to a point and angle in 3D space. Works with any PhysObj, not just physics shadows.
PhysObj:EnableCollisions( boolean enable )
Sets whether the physics object should collide with anything or not, including world. This function currently has major problems with player collisions, and as such should be avoided at all costs. A better alternative to this function would be using Entity:SetCollisionGroup( COLLISION_GROUP_WORLD ).
PhysObj:EnableDrag( boolean enable )
Sets whenever the physics object should be affected by drag.
PhysObj:EnableGravity( boolean enable )
Sets whether the PhysObject should be affected by gravity
PhysObj:EnableMotion( boolean enable )
Sets whether the physobject should be able to move or not. This is the exact method the Physics Gun uses to freeze props. If a motion-disabled physics object is grabbed with the physics gun, the object will be able to move again. To disallow this, use GM:PhysgunPickup.
Vector, Vector PhysObj:GetAABB()
Returns the mins and max of the physics object Axis-Aligned Bounding Box.
Angle PhysObj:GetAngles()
Returns the angles of the physics object in degrees.
Gets the angular velocity of the object in degrees per second as a local vector. You can use dot product to read the magnitude from a specific axis.
Returns the contents flag of the PhysObj.
Returns the linear and angular damping of the physics object.
number PhysObj:GetEnergy()
Returns the sum of the linear and rotational kinetic energies of the physics object.
Entity PhysObj:GetEntity()
Returns the parent entity of the physics object.
Returns the friction snapshot of this physics object. This is useful for determining if an object touching ground for example.
number PhysObj:GetIndex()
Returns the index this physics object is on its PhysObj:GetEntity. Useful for Entity:TranslateBoneToPhysBone.
Vector PhysObj:GetInertia()
Returns the principal moments of inertia (Ixx, Iyy, Izz) of the physics object, in the local frame, with respect to the center of mass.
Returns 1 divided by the angular inertia. See PhysObj:GetInertia
number PhysObj:GetInvMass()
Returns 1 divided by the physics object's mass (in kilograms).
number PhysObj:GetMass()
Returns the mass of the physics object.
Returns the center of mass of the physics object as a local vector.
Returns the physical material of the physics object.
table PhysObj:GetMesh()
Returns the physics mesh of the object which is used for physobj-on-physobj collision.
Returns all convex physics meshes of the object. See Entity:PhysicsInitMultiConvex for more information.
string PhysObj:GetName()
Returns the name of the physics object.
Vector PhysObj:GetPos()
Returns the position of the physics object.
Returns the position and angle of the physics object as a 3x4 matrix (VMatrix is 4x4 so the fourth row goes unused). The first three columns store the angle as a rotation matrix, and the fourth column stores the position vector.
Returns the rotation damping of the physics object.
Returns the angles of the PhysObj shadow. See PhysObj:UpdateShadow.
Returns the position of the PhysObj shadow. See PhysObj:UpdateShadow.
Returns the speed damping of the physics object.
Returns the internal and external stress of the entity.
Returns the surface area of the physics object in source-unitsĀ². Or nil if the PhysObj is a generated sphere or box.
Returns the absolute directional velocity of the physobject.
Returns the world velocity of a point in world coordinates about the object. This is useful for objects rotating around their own axis/origin.
number PhysObj:GetVolume()
Returns the volume in source unitsĀ³. Or nil if the PhysObj is a generated sphere or box.
boolean PhysObj:HasGameFlag( number flags )
Returns whenever the specified flag(s) is/are set.
boolean PhysObj:IsAsleep()
Returns whether the physics object is "sleeping". See PhysObj:Sleep for more information.
Returns whenever the entity is able to collide or not.
Returns whenever the entity is affected by drag.
Returns whenever the entity is affected by gravity.
Returns if the physics object can move itself (by velocity, acceleration)
Returns whenever the entity is able to move.
Returns whenever the physics object is penetrating another physics object. This is internally implemented as PhysObj:HasGameFlag( FVPHYSICS_PENETRATING ) and thus is only updated for non-static physics objects.
boolean PhysObj:IsValid()
Returns if the physics object is valid/not NULL.
Vector PhysObj:LocalToWorld( Vector LocalVec )
Mapping a vector in local frame of the physics object to world frame. this function does translation and rotation, with translation done first.
Vector PhysObj:LocalToWorldVector( Vector LocalVec )
Rotate a vector from the local frame of the physics object to world frame. This function only rotates the vector, without any translation operation.
PhysObj:OutputDebugInfo()
Prints debug info about the state of the physics object to the console.
Call this when the collision filter conditions change due to this object's state (e. g. changing solid type or collision group)
Angle PhysObj:RotateAroundAxis( Vector dir, number ang )
A convinience function for Angle:RotateAroundAxis.
PhysObj:SetAngleDragCoefficient( number coefficient )
Sets the amount of drag to apply to a physics object when attempting to rotate.
PhysObj:SetAngles( Angle angles )
Sets the angles of the physobject in degrees.
PhysObj:SetAngleVelocity( Vector angularVelocity )
Sets the specified angular velocity on the PhysObj
PhysObj:SetAngleVelocityInstantaneous( Vector angularVelocity )
Sets the specified instantaneous angular velocity on the PhysObj
PhysObj:SetBuoyancyRatio( number buoyancy )
Sets the buoyancy ratio of the physics object. (How well it floats in water)
PhysObj:SetContents( number contents )
Sets the contents flag of the PhysObj.
PhysObj:SetDamping( number linearDamping, number angularDamping )
Sets the linear and angular damping of the physics object.
PhysObj:SetDragCoefficient( number drag )
Modifies how much drag (air resistance) affects the object.
PhysObj:SetInertia( Vector angularInertia )
Sets the angular inertia. See PhysObj:GetInertia. This does not affect linear inertia.
PhysObj:SetMass( number mass )
Sets the mass of the physics object. This resets PhysObj:SetBuoyancyRatio (Recalculated based materials' and the physics objects' densities, latter of which is dependent on mass). This is a physics engine limitation.
PhysObj:SetMaterial( string materialName )
Sets the material of the physobject. Impact sounds will only change if this is called on client
PhysObj:SetPos( Vector position, boolean teleport = false )
Sets the position of the physobject.
PhysObj:SetVelocity( Vector velocity )
Sets the velocity of the physics object for the next iteration.
PhysObj:SetVelocityInstantaneous( Vector velocity )
Sets the velocity of the physics object.
PhysObj:Sleep()
Makes the physics object "sleep". The physics object will no longer be moving unless it is "woken up" by either a collision with another moving object, or by PhysObj:Wake. This is an optimization feature of the physics engine. Normally physics objects will automatically "sleep" when not moving for a short while, to save resources, but it can be used for other purposes, for example to temporarily suspend an object mid air.
PhysObj:UpdateShadow( Vector targetPosition, Angle targetAngles, number frameTime )
Unlike PhysObj:SetPos and PhysObj:SetAngles, this allows the movement of a physobj while leaving physics interactions intact. This is used internally by the motion controller of the Gravity Gun , the +use pickup and the Physics Gun, and entities such as the crane. This is the ideal function to move a physics shadow created with Entity:PhysicsInitShadow or Entity:MakePhysicsObjectAShadow.
PhysObj:Wake()
Wakes the physics object, so that it will continue to simulate physics/gravity. See PhysObj:Sleep for more information.
Vector PhysObj:WorldToLocal( Vector vec )
Converts a vector to a relative to the physics object coordinate system.
Vector PhysObj:WorldToLocalVector( Vector WorldVec )
Rotate a vector from the world frame to the local frame of the physics object. This function only rotates the vector, without any translation operation.