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.
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.
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
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.
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.
Returns the mins and max of the physics object Axis-Aligned Bounding Box.
Vector PhysObj:GetAngleVelocity()
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.
number PhysObj:GetContents()
Returns the contents flag of the PhysObj.
Returns the linear and angular damping of the physics object.
Returns the sum of the linear and rotational kinetic energies of the physics object.
table PhysObj:GetFrictionSnapshot()
Returns the friction snapshot of this physics object. This is useful for determining if an object touching ground for example.
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.
Vector PhysObj:GetInvInertia()
Returns 1 divided by the angular inertia. See PhysObj:GetInertia
number PhysObj:GetInvMass()
Returns 1 divided by the physics object's mass (in kilograms).
Vector PhysObj:GetMassCenter()
Returns the center of mass of the physics object as a local vector.
string PhysObj:GetMaterial()
Returns the physical material of the physics object.
Returns the physics mesh of the object which is used for physobj-on-physobj collision.
table PhysObj:GetMeshConvexes()
Returns all convex physics meshes of the object. See Entity:PhysicsInitMultiConvex for more information.
VMatrix PhysObj:GetPositionMatrix()
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.
number PhysObj:GetRotDamping()
Returns the rotation damping of the physics object.
Angle PhysObj:GetShadowAngles()
Returns the angles of the PhysObj shadow. See PhysObj:UpdateShadow.
Vector PhysObj:GetShadowPos()
Returns the position of the PhysObj shadow. See PhysObj:UpdateShadow.
number PhysObj:GetSpeedDamping()
Returns the speed damping of the physics object.
number PhysObj:GetSurfaceArea()
Returns the surface area of the physics object in source-unitsĀ². Or nil if the PhysObj is a generated sphere or box.
Vector PhysObj:GetVelocity()
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.
Returns the volume in source unitsĀ³. Or nil if the PhysObj is a generated sphere or box.
Returns whenever the specified flag(s) is/are set.
Returns whether the physics object is "sleeping".
See PhysObj:Sleep for more information.
boolean PhysObj:IsCollisionEnabled()
Returns whenever the entity is able to collide or not.
boolean PhysObj:IsDragEnabled()
Returns whenever the entity is affected by drag.
boolean PhysObj:IsGravityEnabled()
Returns whenever the entity is affected by gravity.
boolean PhysObj:IsMotionEnabled()
Returns if the physics object can move itself (by velocity, acceleration)
boolean PhysObj:IsMoveable()
Returns whenever the entity is able to move.
boolean PhysObj:IsPenetrating()
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.
Mapping a vector in local frame of the physics object to world frame.
this function does translation and rotation, with translation done first.
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.
PhysObj:RecheckCollisionFilter()
Call this when the collision filter conditions change due to this object's state (e. g. changing solid type or collision group)
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: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.
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.
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: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.
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.
Converts a vector to a relative to the physics object coordinate system.
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.