From Valve Developer Community
Jump to: navigation, search

VPhysics is Source's built-in 3D physics simulation engine. VPhysics objects move and collide believably thanks to the system's simulation of mass, gravity, friction, air resistance, inertia and buoyancy.

VPhysics was originally created by incorporating Ipion Virtual Physics, a physics middleware acquired and since licensed by Havok. The successor to VPhysics on Source 2 is Rubikon.

Collision models

Dr. Breen's jointed collision mesh.

VPhysics objects ("collision models") are invisible, because in order for the simulation to be efficient they must be extremely simple. The visible part of an entity will obviously be a close match to the shape of the VPhysics object, but it is entirely ignored by the simulator.

Collision models are typically loaded from a collision mesh embedded inside an entity's assigned model, but they can also be generated, from a bounding box for instance. Spherical collision models are also possible.

Tip:You can see collision meshes with the console command vcollide_wireframe 1.


VPhysics co-exists with QPhysics (a retroactive name - it's only ever referred to in the codebase as "game physics"), an older and far less sophisticated simulator that Source inherits from Quake. QPhysics is still used for players and walking NPCs because full VPhysics would lead to situations too complex for either AI or players to handle. Vehicles and flying NPCs do use VPhysics, however.

QPhysics entities are given a VPhysics "shadow" that allows them to interact with VPhysics entities in a limited way.


In programming terms, VPhysics is an engine library that takes direct control of the motion of an entity. When it is in full effect QPhysics positioning functions cease to have any effect, and the object's behaviour is instead influenced through the application of forces and constraints (though direct modification is still possible).

This spawn function creates a physically-simulated model:

#define MODEL "models/props_c17/FurnitureDresser001a.mdl"

void CMyEnt::Spawn()


There initialisation functions are:

Used above. Makes the entity a free VPhysics object with full simulation and collisions.
An object that never moves.
VPhysicsInitShadow( bool allowPhysicsMovement, bool allowPhysicsRotation, solid_t *pSolid = 0 )
An object that collides with other VPhysics objects, but has its location defined by the QPhysics motion of its entity. This can lead to very strong forces being exerted on normal VPhysics objects, so use with care!

Unlike VPhysicsInitNormal(), neither of the functions above implicitly call SetSolid(). You will need to do so yourself as the default SOLID_NONE causes both to return early.

Note:SetSolid() alone does not enable VPhysics collisions.


Measurement Unit
Distance Inches
Mass Kilogrammes
Volume Cubic inches
Velocity Inches per second
Acceleration Inches per second per second
Density Kilogrammes per cubic metre
Force Inches per second per kilogramme
Torque Degrees per second per kilogramme

See also Origin and QAngle.


A VPhysics environment within which objects are simulated. New IPhysicsObjects are created here, and global settings like gravity can be configured.
IPhysicsEnvironment* physenv is created by default. Multiple environments are entirely possible, which is how Portal works.
The core interface into a VPhysics object. Provides functions for tweaking parameters and applying forces. An entity can have multiple IPhysicsObjects (e.g. ragdolls).
Provides various CPhysCollide and CPhysConvex (see below) utilities. Use the physcollision global instance.
A rigid collision mesh. Despite being named like a server entity, this class is defined in the engine. It can be passed to various IPhysicsCollision functions.
A collection of CPhysCollides.
A single, convex collision mesh element.
A collection of raw polygons that represent a collision mesh. Call physcollision->ConvertPolysoupToCollide() to "compile" it to a CPhysCollide.
A collection of data passed to the engine when creating new physics objects.

See also

Notable VPhysics entities