IPhysicsObject
IPhysicsObject
is the basic representation of a rigid VPhysics object. It is shared between the server, client and VPhysics libraries.
Getting and setting
- If you just want to create a physics object for your entity's model, use a
VPhysicsInit*()
function. - An entity's main physics object can be accessed with
CBaseEntity::VPhysicsGetObject()
, while a list of all its objects is returned byVPhysicsGetObjectList()
. - New
IPhysicsObject
s can be created with thephysenv->Create*()
functions, or with the globalPhysModelCreate*()
helpers.Note:Remember to callphysenv->DestroyObject()
when you no longer need these.
Member functions
State
Wake()
Sleep()
- To improve performance physics objects will go to sleep after a second or so of inactivity. They will be woken by interaction with another object, but not by changes to their own internal state. If you change a simulation property of the object and want it to respond immediately, make sure that you
Wake()
it! GetCollide()
- Gets this object's
CPhysCollide
(the actual geometry it represents). BecomeTrigger()
RemoveTrigger()
- Confirm:The object stops colliding with other objects, but still triggers
Touch()
? EnableCollisions()
EnableGravity()
EnableDrag()
EnableMotion()
- Various simulation features that can be enabled or disabled per-object.
Properties
SetMass()
SetInertia()
- Overrides this object's mass (in kilos) and inertia (Todo: units; it's a vector).
SetDamping()
- Confirm:Sets rotation damping (how fast the object stops spinning)
SetDragCoefficient()
- Set friction. Todo: Units
SetBuoyancyRatio()
- Sets how much upward force is exerted on the object (relative to its mass) whenever it is in water. 0 means that the object sinks, while >1 results in the object bouncing off the surface with increasing violence.
- Source does not simulate water pressure, so genuine buoyancy is not possible.
Forces
ApplyForceCenter()
ApplyForceOffset()
- Applies a inch per second per kilogram force relative to the world. If you specify an offset the force comes from a specific location, otherwise it applies evenly across the whole object.
ApplyTorqueCenter()
- Applies a degrees per second per kilogram ([confirm]) rotation relative to the world.
AddVelocity()
SetVelocity()
SetVelocityInstantaneous()
- Adds or sets velocity (inch/s) and torque (degrees/s) in a physically incorrect way that affects the object regardless of its current mass/inertia.
SetPosition()
SetPositionMatrix()
- Teleports the object to a new location. Todo: Impact of teleporting an object short distances every frame vs. letting it find its own way.
Multiple IPhysicsObjects
An entity can represent up to 1024 IPhysicsObject
s. This happens in Valve's code with vehicle wheels and whenever a model has $collisionjoints (the "must all be convex" limitation of which is imposed by studiomdl, not the engine).
Note:Avoid simulating completely separate physics objects with one entity. Although VPhysics doesn't care one way or the other, game systems which use bounding boxes will become very inefficient should the objects become far apart. You will also encounter problems with QPhysics velocity calculations when the "main" object is moving but others aren't (or vice versa). It's probably possible to work around all of these issues with the mod SDK, but only after a lot of work!