Vphysics & Qphysics: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
m (→‎Basic Concepts: Unicodifying)
 
(34 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{wip}}
== Mechanics of Motion ==
Source uses four methods to simulate the effects Mechanical Forces on the Motion of World Objects in game:
# Particle-simulated objects : Source Particle Motion appears to be scripted? See [[info_particle_system]]. Particles are never Solid.
# Ray-simulated objects : very small objects travelling at infinite speed are simulated as simple but accurate, straight-line ray-traces. They are not treated as Solid, until they hit a Solid Object.
#* LOS tests are raytraced until blocked by an opaque surface (eg normal Solid surface is Solid to LOS). Range is also restricted to 2048 units (or more - see [[NPC_Sensing]]) and affected by [[env_fog_controller]] limited visibility.
#* Bullets are also Ray-traced. Some surfaces (eg Grates) are NotSolid to Bullets. Their Range is determined by ... ?
# Hull-simulated objects : have simple, Solid Collision boxes which are moved by a controlling intelligence (or script), and only restricted by simple QPhys collisions and QPhys gravity.
# VPhysics-simulated objects are either Rigid or Deformable :
#* VPhys [http://en.wikipedia.org/wiki/Rigid_bodies Rigid Body] : position ($origin) affected by VPhys Translational Motion ''plus'' orientation ($angles) affected by VPhys Rotational Motion (which requires a Collision Model)
#** VPhys [[$concave]] Rigid Body : = unbreakable (rigid) constraints holding physboxes (bones?) together?
#* VPhys [http://en.wikipedia.org/wiki/Deformable_body Deformable Body] is a ''constrained'' system of Rigid Bodies:
#** VPhys Ragdoll object made of bones?: joints = (flexible) contraints allowing limited articulation by external forces.
#** VPhys(?) Breakable object made of gibs: health = (rigid) constraints holding gibs together, damage = external force.
{{TODO|what is the correct term for a single piece of convex geometry within a concave or jointed collision model? a PhysBox? a PhysBone? ... some $bones in a Ragdoll may be NotSolid to Collision.}}
=== Basic Concepts ===
* '''Linear Motion''' is a change in the Location of the entity's [[origin]] in the World.
** '''[http://en.wikipedia.org/wiki/Force Push]''' attempts to increase the distance between the objects: eg Collisions, Gravgun Attack1, Explosion, Wind, etc.
** '''[http://en.wikipedia.org/wiki/Force Pull]''' attempts to decrease the distance between the objects: eg Constraints, Gravgun Attack2, Gravity, etc.
* '''Angular Motion''' is a change in the Orientation ($angles) of the object in the World.
** '''[http://en.wikipedia.org/wiki/Torque Torque]''' attempts to rotate or spin the object about its own Center of Mass: eg Angular Deflection, Stability, [[func_rotating]], [[phys_motor]], [[point_viewcontrol]]


Both systems basically govern (partially or completely) the Motion of Solid World Objects in game by simulating the effects Mechanical Forces upon them.


1. Mechanical Motion:
* '''Mass''' of an object is its ''[http://en.wikipedia.org/wiki/Mass#Inertial_mass Inertial Mass]'' ie its resistance to acceleration.
* Translational Motion affects the $origin (position) of the object.
*: Mass appears to have negligible affect on Torque, but Center of Mass is very important.
* Rotational Motion affects the $angles (orientation) of the object.
*: Game constant : Water = 1kg/liter = 28.3 kg/cubic foot (= 6.9 gram / map unit³?)


2. Mechanical Forces:
:* '''Static''' objects cannot be moved by VPhys or QPhys forces. In effect, a static object has infinite ''inertial mass''. This makes them very cheap in terms of VPhysics calculations.
Traditionally there are only the first two, but because Translational and Rotational Motion are handled quite differently by each system, I've added "Spin" which is can be a Push, Pull or Both that applies a Rotational Force to the object.
::* [[movement hierarchy]], [[constraint]]s ...?
* Push : eg Collisions, Gravgun Attack1, Explosion, etc.
* Pull : eg Constraints, Gravgun Attack2, Gravity, etc.
* Spin : eg Angular Collisions, Stability, [[func_rotating]], [[phys_motor]], [[point_viewcontrol]]


:* '''Solidity''' : The Solid [[CollisionProperty]] generally means this object will attempt to ''Block Motion'' of other Solid objects. But there's also ''Block Bullets'' and ''Block LOS'' Collision Properties.
::* Solidity is a [[boolean]], either Solid or NotSolid. The Viscosity of Water, etc are handled separately. (see below).
::* A Solid object is basically anything which has Mass.
::* Physicsmode:
::: 1 : Solid, pushes the player away.
::: 2 : Non-solid, but gets pushed away by the player.
::: 3 : Non-solid, clientside simulated only.


The VPhysics Engine determines [http://en.wikipedia.org/wiki/Rotational_motion#Translation_and_Rotation Translational Motion and Rotational Motion] of VPhys Objects resulting from the interaction of various (simulated) VPhys Forces. It is a kind of Procedural Animation Engine designed to simulate [http://en.wikipedia.org/wiki/Classical_mechanics Classical Mechanics].
:* '''Volume''' : CollisionModel ...


Not knowing if there is a real name for this, I have dubbed all the non-VPhysics simulation stuff "QPhysics" ( for "Quake Physics" - because I guess this is where it comes from). QPhys is not nearly as sophisticated as VPhys, but equally important as it is used to determine the Motion of all Hull-simulated NPCs and Players, several types of projectile and a number of Moving Brush Entities (eg func_door, etc).


* '''Velocity'''
: Velocity is a [[vector]]; it has both magnitude (speed) and direction. <code>Velocity = Time * Acceleration / Mass</code>.
: Maximum Velocity of an object is achieved when the forces of acceleration and deceleration are balanced. Deceleration is usually caused by Friction, eg Air Resistance, Surface Friction.
:* '''[http://en.wikipedia.org/wiki/Gravity#Equations_for_a_falling_body Gravity]''' ''accelerates'' objects at 32 ft/sec&sup2; (= 21.9 mph/sec)
::* Game variable (Gravity = 1 by default) seems to be applied equally to both VPhys and QPhys calculations ...
::* {{TODO| does changing gravity affect trajectory of crossbow bolt, etc ?}}


== Objects ==
:* '''[http://en.wikipedia.org/wiki/Drag_%28physics%29 Air Resistance]''' or Aerodynamic Friction ''decelerates'' objects moving through ''Air''.
::* Hull-objects use a simple "max speed" value for "flying", "running", etc. specified per Entity Class.
:::* Freefalling Hull-objects use a worldconstant [http://en.wikipedia.org/wiki/Terminal_velocity Terminal Velocity] = 3500 units/sec (218.75 ft/sec) (ie reached after 6.8 sec of freefall).
::* VPhys-objects use {{TODO|...?}}.
::* Wind Forces ...
<!--
* Viscosity is measured in Pascal-seconds = 1 kg·m−1·s−1. If a fluid with a viscosity of one Pa·s is placed between two plates, and one plate is pushed sideways with a shear stress of one pascal, it moves a distance equal to the thickness of the layer between the plates in one second. It decreases as temperature increases. eg
Temp  Water  Air
10&deg;C  1.3  0.017  mPa
20&deg;C  1.0  0.018  mPa
30&deg;C  0.8  0.019  mPa
-->
:* '''[http://en.wikipedia.org/wiki/Drag_%28physics%29 Water Resistance]''' or Hydrodynamic Friction ''decelerates'' objects moving through ''Water''.
::* Hull-objects use a simple "max speed" value for "surface swim" and "underwater swim" (if they don't just drown) specified per Entity Class.
:::* Sinking Hull-objects ... Player sinks at 48 units/sec (3 ft/sec) {{TODO| check that NPCs sink at same speed ?}}.
::* VPhys-objects use {{TODO|... ?}}.
::* Water is approx 50-100 times more viscous than air than air ... [http://en.wikipedia.org/wiki/Newtonian_fluid Newtonian Fluid]?
::* Current Forces ...


:* '''[http://en.wikipedia.org/wiki/Coefficient_of_friction Surface Friction]''' between two parallel solid surfaces in contact = Perpendicular Pressure * Friction Coefficient:
::* Perpendicular Pressure : eg Object's on a Horizontal surface, Weight*Friction = resistance to ''sliding'' Horizontal movement.
::* Friction Coefficient is specific to each combination of surfaces; eg Rubber & Wood, Metal & Wood, Rubber & Metal, Rubber & Rubber,  ... [http://www.engineeringtoolbox.com/friction-coefficients-d_778.html  look-up table] in Materials System ?
::* Sliding on [http://en.wikipedia.org/wiki/Slope Slope] : where F = Friction Coefficient, object will slip on rise:run of <code>1:1/F</code> or steeper. So if F = 1, slope = 1:1, if F = 0.5, slope = 1:2, etc
::* Sliding on Tilt Angle : where F = Friction Coefficient, and A = Angle of Elevation: <code>F = tan A</code>. So F 1 = 45&deg;, F 0.5 = 26.6&deg;, F 2 = 63.4&deg;([http://www.tribology-abc.com/abc/friction.htm calc])


== Physics Consistency ==


A VPhys object is a [http://en.wikipedia.org/wiki/Physical_body Physical Body] It is Solid and can Move :
Whilst the scientific field of [http://en.wikipedia.org/wiki/Physics Physics] describes interactions between all physical phenomena (including the behaviour of light, sound, heat, etc), the Source Physics Engine(s) deal exclusively with [http://en.wikipedia.org/wiki/Mechanics Mechanical] interactions between Solid objects in the World.
* VPhys [http://en.wikipedia.org/wiki/Rigid_bodies Rigid Body] : position ($origin) affected by VPhys Translational Motion ''plus'' orientation ($angles) affected by VPhys Rotational Motion (which requires a Collision Model)
** VPhys [[$concave]] Rigid Body : = unbreakable (rigid) constraints holding physboxes (bones?) together?
* VPhys [http://en.wikipedia.org/wiki/Deformable_body Deformable Body] is a ''constrained'' system of Rigid Bodies:
** VPhys Ragdoll object made of bones?: joints = (flexible) contraints allowing limited articulation by external forces.
** VPhys(?) Breakable object made of gibs: health = (rigid) constraints holding gibs together, damage = external force.
{{todo|what is the correct term for a single piece of convex geometry within a concave or jointed collision model? a PhysBox? a PhysBone? ... some $bones in a Ragdoll may be NotSolid to Collision}}


A QPhys Objects may also be Solid and may also Move:
An important aspect of Source gameplay is that the physical interactions between World objects remains reasonably consistent and predictable. There would be no point in using a physical-mechanics simulation system that wasn't. (Actually, level designers frequently use physics as a "special effect" - so, given we are making games here [not scientific simulations], level designers should have more control over the implementation of physics in each given context.) For technical (legacy) and CPU performance optimisation reasons, not all World objects can be physically simulated to the same level of detail.
* Particle Objects : Source Particle Motion appears to be scripted? See [[info_particle_system]]. (Brownian motion & Fluid Dynamics are not simulated!)
* Hull Objects : (see below)
* Ray Objects : travel at infinite speed and are very small, so they are simulated as simple. but accurate, straight-line ray-traces, or Vectors, having direction and range.
** LOS tests are raytraced to 2048 units (or more - See NPC_Sensing) if not blocked by an opaque surface (eg normal Solid surface is NOTSolid to LOS) or [[env_fog_controller]] limited visibility.
** Bullets are also Ray-traced. Some surfaces (eg Grates) are NotSolid to Bullets. Their Range is determined by ... ?


Projectile Gravity Deflection Impact Damage Mechanics NPC Push
'''VPhysics''' is derived from the Havok Physics Engine, and determines the Linear and Angular Motion of ''VPhys Objects'' resulting from the interaction of various (simulated) ''VPhys Forces''. It is a kind of Procedural Animation Engine designed to simulate [http://en.wikipedia.org/wiki/Classical_mechanics Newtonian Mechanics]. The '''Gravgun''' is a key part of the VPhys system, enhancing the Player's ability to influence VPhys Objects and events. <!-- Gravgun can only Push/Pull VPhys Objects (if mass and range are < ?). It cannot Push/Pull Ray- or Hull-simulated objects. However, Gravgun Push can cause Damage to NPCs. -->
LOS test no no none Ray no
bullet no no skill.cfg Ray no?
grenade-SMG yes no (explode) no? Hull? no?
crossbow bolt yes no (impale) skill.cfg Hull? no
rocket no no (explode) no? Hull no?
NPC/Player yes no ? Hull yes
grenade-frag VPhys VPhys ? VPhys yes?
grenade-AR2 no ? VPhys ? VPhys yes?
gravgun-prop VPhys VPhys ? VPhys yes?


* Gravity : Will Gravity affect its Trajectory (Translational Motion).
'''QPhysics''' (Likely stands for "Quake Physics") is not nearly as sophisticated as VPhys, but equally important as it is used in determining the Motion of all Hull-simulated NPCs and Players, several types of projectile and a number of Moving Brush Entities (eg func_door, etc).
* Deflection : Will it bounce/ricochet off a solid object rather than simply stopping ? (Translational & Rotational Motion)
* Impact Damage : Excluding explosion damage (defined in skill.cfg). Presumambly derived from Projectile's Momentum (kinetic energy). VPhys calculated or look-up table ?
* Mechanics : Physics interaction simulation system used.
{{note|Gravgun Test: Gravgun can only Push/Pull VPhys Objects (if mass and range are < ?). It cannot Push/Pull Ray- or Hull-objects. However, Gravgun Push can cause Damage to NPCs.}}
* NPC Push : All projectiles (except LOS test) will Push VPhys Objects (eg ragdolls), but can they affect (stop/slow/deflect) an NPC's momentum? Isn't there something like this in DOD? Hull Motion seems to be entirely immune to external (VPhys) forces unless specifically scripted otherwise - eg Combine_Soldier melee attack: Push back player ?. What about Rocket Jumping in TF2?


The biggest difference is that VPhysics alone determines the motion and behaviour of Vphys Objects, whereas QPhysics merely imposes a few simple restrictions on objects that are primarily controlled by either Player Input, NPC AI, an I/O script, Scripted Animation Sequence, Entity Script, etc, etc.


== QPhysics Interactions ==
{{TODO| Where do these "physics interactions" fit in ?}}
* Heat System : Flammable objects & fire spreading between them.
* Damage System : Breakable objects, Falling & Impact Damage calculations
* Gravgun Attack1 'knock-back' effect on Antlions, Manhacks, Scanners, etc
 
== Projectiles ==
 
* A VPhys object can be Pushed or Damaged by anything (solid) that hits it - Bullet, Hull, or other VPhys object.
* A Bullet (ray) is so small and fast that nothing can Push or Damage it.
* All explosions push and damage VPhys objects. Hulls may be damaged.
 
Projectile Gravity Deflection Impact Damage Solid Model NPC Push
bullet no no skill.cfg Ray no?
grenade-SMG yes no (explode) no? Hull? no?
crossbow bolt yes no (impale) skill.cfg Hull? no
rocket no no (explode) no? Hull no?
NPC/Player yes no no? Hull yes
grenade-frag VPhys VPhys yes? VPhys yes?
grenade-AR2 no ? VPhys yes? VPhys yes?
gravgun-prop VPhys VPhys yes? VPhys yes?
explosion no no no VPhys no
func_door no no? crush? Hull? yes?
 
* Gravity : Will Gravity affect its Trajectory (Linear Motion).
 
* Deflection : Will it bounce/ricochet off a solid object rather than simply stopping ? (Linear & Angular Motion)
 
* Impact Damage : Will it inflict damage on collision (excluding explosion damage defined in skill.cfg).
: Presumambly derived from Projectile's Momentum (kinetic energy): calculated or look-up table ?
:: Constraint is a static pull force; it resists movement away. ?
: [[Impact Damage Table]] suggests vphys object mass is classed ("tiny, small, medium and large") relative to "Player, Player in Vehicle, NPC or Glass". Damage clamps & multipliers are specified for some classes, but the basic calculation ... ?
: [[Prop Data#Damage Modifiers]] for "bullet, club, explosive" are only applied to breakable-props.
:: why should glass use a damage_table plus prop_data dam-mods ?
 
* Solid Model : Physics interaction simulation system used.
 
* NPC Push : Some collisions seem to affect (stop/slow/deflect) an NPC's Hull Momentum? Isn't there something like this in DOD? Hull Motion seems to be entirely immune to external (VPhys) forces unless specifically scripted otherwise - eg Combine_Soldier melee attack: Push back player ?. What about Rocket Jumping in TF2?
<!--** Something to do with vphys-prop's physicsmode: {{physicsmode_choices}}-->
 
* {{TODO| Are Collision Hulls really boxes? They seem to behave more like Cylinders in game. Eg A Player should not be able to walk diagonally (W+A) along a 34 unit passageway, as the diagonal dimension of his 32x32 Hull would be 45 units. For that matter, he would not be able to rotate (much) either. Cylinders don't have corners to catch on things and cause rotational deflection. The test would be an octagonal hole ...}}
 
== Hull QPhysics Interactions ==
 
* Hull Translation and Rotation Motion : controlled by PlayerInput/AI/IO/WeaponScript/etc ...
: nb: dynamic light, turret & camera entities can track a moving target<target_destination>.
 
* Hull Gravity: eg Jump Trajectory. Alternative, separate Gravity system to VPhys ... ?
 
* Hull Linear Deflection : Static Solids cause Hulls to simply stop moving. Deflection/Ricochet/Knock-Back is not simulated.
 
* Hull Angular Deflection : vectors striking a hitbox but not passing through the CofMass do not induce rotation. Not simulated.
 
* Hull Friction : There is definitely some kind of Player Hull friction simulation going on in 33 unit passageways.
:: Mud material reduces Player movements through it's own mechanism, not VPhys.
 
* Hull Impact Damage : Fall Damage to Player/NPC. Impact Damage to breakable object he lands on.... [[Impact Damage Table]]s.


* What about [[Player Hull]], [[NPC Hull]], etc Physics ?
* QPhys Translation and Rotation Motion : controlled by PlayerInput/AI/IO/WeaponScript/etc ...
* QPhys Trajectory : eg Jump Trajectory. Alternative, separate Gravity system to VPhys?
* QPhys Deflection : Static Solids cause Hulls to simply stop moving. Deflection/Ricochet/Knock-Back (Newton's reciprocal Push force) is not simulated. But Sliding Friction?
* QPhys Impact Damage : Fall Damage to Player? Impact Damage to breakable object?
* '''Physics Shadow''': "If Players don't have a physics shadow they can't move objects just by touching them; they have to press USE to apply a pushing force" (from [[Alternate Multiplayer Physics]]).
* '''Physics Shadow''': "If Players don't have a physics shadow they can't move objects just by touching them; they have to press USE to apply a pushing force" (from [[Alternate Multiplayer Physics]]).
* QPhys Friction :  
** compare [[physicsmode_choices]] per prop_phys_mp : "Solid, pushes player away" vs "Non-solid, but gets pushed away by the player".
: Mud material reduces Player movements through it's own mechanism, not VPhys.


* QPhys Push Entity (eg [[trigger_push]])
* QPhys Pull Entity (eg [[point_playermoveconstraint]])
* QPhys Spin Entity (eg [[point_viewcontrol]]? [[func_rotating]]?
: What about Animated Brushes: func_door, func_rotating ... can they be blocked by a Hull? they use Hull Collision?


* {{todo| Are Collision Hulls really boxes? They seem to behave more like Cylinders in game. Eg A Player should not be able to walk diagonally (W+A) along a 34 unit passageway, as the diagonal dimension of his 32x32 Hull would be 45 units. For that matter, he would not be able to rotate (much) either.
== Collision Event ==


# Collision Detection - if projectile touches target's Bounding Box :
#* If projectile = bullet, test against target's Hitbox and then [[CollisionProperty]]
#* If projectile = Hull or VPhys, test against target's CollisionModel ?
# Calculate Angular Force of Impact on both objects; ie
#* projectile's movement vector in relation to center of mass of target
#* projectile's movement vector in relation to center of mass of projectile
# Projectile Momentum absorbed by / transferred to:
## damage to target
## damage to projectile
## angular deflection (spin force) on target (unless t = Hull)
## angular deflection (spin force) on projectile (unless p = Hull)
## linear deflection (push vector) on target
## linear deflection (bounce vector) on projectile (unless p = Hull)


=== VPhys Object Properties ===
== Mechanical Properties & Interactions ==


* [http://en.wikipedia.org/wiki/Friction Coefficient of Friction] ([[scale]] applied to CofMomentum?)
* Qphys Collision Hull
: Sliding Friction is a 2-material interaction ... lookup table in Material System?
: Geometry & rigging = is bbox-defined in Entity Class (eg [[NPC Hull]], [[Player Hull]], projectile hulls?)
: Is Static Friction simulated in VPhys ?
: Player & NPC Hull always have "square" footprint. Player & some NPCs have multiple Hulls eg Player's DUCK_HULL and OBS_HULL.
* [http://en.wikipedia.org/wiki/Mass Mass] (= [[scale]] ... for  / kinetic energy?)
: '''Ground Hull''': Origin = center of the base face; '''Flying Hull''' (''centered hull'') Origin = geometric center of box.
: For Inertia & Momentum in both Rotational and Translational VPhys.
: Qhull is not deflected by linear vphys forces. Solid obstacles simply block movement.
* [http://en.wikipedia.org/wiki/Center_of_mass Center of Mass] (CofMass) (= [[coords]] relative to $origin: "0 0 0 1")
: Qhull cannot rotate so not deflected by angular forces. Qhulls are always [http://en.wikipedia.org/wiki/Bounding_volume AABB to world axes] - any Entity rotation is not applied to Qhull.
: For Rotational VPhys.
* Collision Model (=IPhysicsObject?)(= set of [[coords]] relative to $origin: (?), eg "16 16 72 1")
: defined by physbox.mdl or brush vertices.
: For Rotational VPhys. (This might be translated into tetrahedra: Triangles relative to $CofMass?)
* Volume calculated from CollisionModel or simply a keyvalue (maybe $density) ?


== VPhys Forces ==
* Vphys Collision Model (=IPhysicsObject?)
: Geometry & Rigging is vertex-defined in [[Studiomodel]].phy (or [[func_physbox]])
: Vphys hull rotation induces rotation of EntityOrigin or BoneOrigin.
: Vphys forces act on Collisionmodel (Vphys hulls), causing the Entity to move and/or rotate.
: Collision Model total Volume is calculated for [[$automass]]


* World VPhys Properties (ie Constant values applicable to all VPhys Objects)
:* Rotation : [http://en.wikipedia.org/wiki/Center_of_Momentum Center of Momentum] = [[vector]]: Center of Mass * "internal forces"
** Gravity (Constant Pull Force) = [[vector]] "0 0 1 0"
:: Angular Momentum (ie spinning about Center of Mass) as opposed to Linear Momentum (ie linear velocity of Center of Mass)
** Solidity ([[CollisionProperty]]) = [[boolean]]
:: By default: Center of mass/rotation is aligned to [[ModelOrigin]] and [[EntityOrigin]] = geometric center of bounding box.
** Density of Water = 1


* Impact Damage (to both colliding objects)
:* Rotation : Settling / Stability
* VPhys Push
:: Gravity applies as Torque about the CofMass until CollModel (Fulcrum) provides stable support.
* VPhys Pull
:: Collision Model might be translated into a collection of tetrahedra/tripods: Triangles relative to $CofMass?
* VPhys Spin eg [[phys_motor]]
::: so Rotational Stability = Triangular "foot" perpendicular to Center of Momentum vector.


== VPhys Interactions==
* Impact Damage & Vphys push (to both colliding objects): -- does damage absorb momentum?
: Flex - ie ragdoll model
: Break - ie breakable model
: Explode -


=== Translational Events ===
== Player & NPC Hulls ==
<!--
From '''ai_hull.cpp''' I got this vector data, which I have tried to interpret into box dimensions. The first pair of coords seem likely to describe the collision hull, but the second set of coords ... ? :
-->
Hull Type              Hull-1 vectors                  Hull-2 vectors                  Hull-1 dimensions    Hull-2 dimensions
Ground Nav NPC (from ai_hull.cpp)
*  Tiny_Hull (-12,-12,  0), (12, 12,  24), (-12,-12,  0), (12, 12,  24) = 24 x 24 x 24 ==  24 x 24 x 24
*  Human_Hull (-13,-13,  0), (13, 13,  72), ( -8, -8,  0), ( 8,  8,  72) = 26 x 26 x 72 &/  16 x 16 x 72
*  Wide_Human_Hull (-15,-15,  0), (15, 15,  72), (-10,-10,  0), (10, 10,  72)  = 30 x 30 x 72 &/  20 x 20 x 72
*  Medium_Hull (-16,-16,  0), (16, 16,  64), ( -8, -8,  0), ( 8,  8,  64) = 32 x 32 x 64 &/  16 x 16 x 64
*  Medium_Tall_Hull (-18,-18,  0), (18, 18, 100), (-12,-12,  0), (12, 12, 100) = 36 x 36 x 100 &/  24 x 24 x 100
*  Wide_Short_Hull (-35,-35,  0), (35, 35,  32), (-20,-20,  0), (20, 20,  32)  = 70 x 70 x 32 &/  40 x 40 x 32
*  Large_Hull (-40,-40,  0), (40, 40, 100), (-40,-40,  0), (40, 40, 100) = 80 x 80 x 100 ==  80 x 80 x 100
Air Nav NPC (from ai_hull.cpp)
*  Tiny_Centered_Hull ( -8, -8, -4), ( 8,  8,  4), ( -8, -8, -4), ( 8,  8,  4) = 16 x 16 x  8 ==  16 x 16 x  8
*  Small_Centered_Hull (-20,-20,-20), (20, 20,  20), (-12,-12,-12), (12, 12,  12) = 40 x 40 x 40 &/  24 x 24 x 24
*  Large_Centered_Hull (-38,-38,-38), (38, 38,  38), (-30,-30,-30), (30, 30,  30) = 76 x 76 x 76 &/  60 x 60 x 60
Player (from gamerules.cpp)
  * (normal)_HULL (-16,-16,  0), (16, 16,  72),                         = 32 x 32 x 72
  * DUCK_HULL         (-16,-16,  0), (16, 16,  36),                         = 32 x 32 x 36
  * OBS_HULL         (-10,-10,-10), (10, 10,  10),                         = 20 x 20 x 20
note: All Hulls have a square footprint with the origin in its centre.
note: Ground nav Hulls' $origin is at the base of the vertical axis, whereas Air-nav (_Centered_Hull) $origin is mid-vertical axis.
note: The mysterious NPC Hull-2 always fits inside Hull-1, and shares the same axes of symmetry as Hull-1.


* [http://en.wikipedia.org/wiki/Center_of_Momentum Center of Momentum] ([[vector]]: CofMass * exteranl forces)
== Force Entities ==
* [http://en.wikipedia.org/wiki/Trajectory Trajectory] (gravity deforms translational motion)
* [http://en.wikipedia.org/wiki/Deflection#Physics Collision Deflection] (trajectory & collision model)


=== Rotational Events ===
* QPhys Push Entity (eg [[trigger_push]])
 
* QPhys Pull Entity (eg [[point_playermoveconstraint]])
* Settling (Gravity induces Rotational Motion about the CofMass until CollModel provides stable support)
* QPhys Spin Entity (eg ... rather difficult ... [[point_viewcontrol]] [[func_door]] (use Hull Collision?)
* [http://en.wikipedia.org/wiki/Rotational_motion#Torque Torque] (rotational inertia)


== Collision Events ==
* VPhys Push Entity (eg [[phys_thruster]])
1. Collision Detection - (see CollisionProperty]]) (occurs before VPhys simulation)
* VPhys Pull Entity (eg [[phys_constraint]])
2. Calculate (Angular) Force of Impact (on both objects)
* VPhys Spin Entity (eg [[phys_motor]], [[phys_thruster]] with torque, )
3. Deformation (does either object bend or break?) (can the other object move?)
4. Rotational Deflection (CollisionModel settles under object's CofMomentum)
5. Translational Deflection (resulting CofMomentum becomes Translational Motion)
6. Translational Motion (Gravity deforms Trajectory)
7. Next Collision Detection


== Damage Events ==
[[Category:QPhysics]]
? not sure this is really part of VPhys at all.
[[Category:VPhysics]]
{{stub|wow, all these TODOs}}

Latest revision as of 02:14, 9 January 2024

Mechanics of Motion

Source uses four methods to simulate the effects Mechanical Forces on the Motion of World Objects in game:

  1. Particle-simulated objects : Source Particle Motion appears to be scripted? See info_particle_system. Particles are never Solid.
  2. Ray-simulated objects : very small objects travelling at infinite speed are simulated as simple but accurate, straight-line ray-traces. They are not treated as Solid, until they hit a Solid Object.
    • LOS tests are raytraced until blocked by an opaque surface (eg normal Solid surface is Solid to LOS). Range is also restricted to 2048 units (or more - see NPC_Sensing) and affected by env_fog_controller limited visibility.
    • Bullets are also Ray-traced. Some surfaces (eg Grates) are NotSolid to Bullets. Their Range is determined by ... ?
  3. Hull-simulated objects : have simple, Solid Collision boxes which are moved by a controlling intelligence (or script), and only restricted by simple QPhys collisions and QPhys gravity.
  4. VPhysics-simulated objects are either Rigid or Deformable :
    • VPhys Rigid Body : position ($origin) affected by VPhys Translational Motion plus orientation ($angles) affected by VPhys Rotational Motion (which requires a Collision Model)
      • VPhys $concave Rigid Body : = unbreakable (rigid) constraints holding physboxes (bones?) together?
    • VPhys Deformable Body is a constrained system of Rigid Bodies:
      • VPhys Ragdoll object made of bones?: joints = (flexible) contraints allowing limited articulation by external forces.
      • VPhys(?) Breakable object made of gibs: health = (rigid) constraints holding gibs together, damage = external force.
Todo: what is the correct term for a single piece of convex geometry within a concave or jointed collision model? a PhysBox? a PhysBone? ... some $bones in a Ragdoll may be NotSolid to Collision.

Basic Concepts

  • Linear Motion is a change in the Location of the entity's origin in the World.
    • Push attempts to increase the distance between the objects: eg Collisions, Gravgun Attack1, Explosion, Wind, etc.
    • Pull attempts to decrease the distance between the objects: eg Constraints, Gravgun Attack2, Gravity, etc.
  • Angular Motion is a change in the Orientation ($angles) of the object in the World.


  • Mass of an object is its Inertial Mass ie its resistance to acceleration.
    Mass appears to have negligible affect on Torque, but Center of Mass is very important.
    Game constant : Water = 1kg/liter = 28.3 kg/cubic foot (= 6.9 gram / map unit³?)
  • Static objects cannot be moved by VPhys or QPhys forces. In effect, a static object has infinite inertial mass. This makes them very cheap in terms of VPhysics calculations.
  • Solidity : The Solid CollisionProperty generally means this object will attempt to Block Motion of other Solid objects. But there's also Block Bullets and Block LOS Collision Properties.
  • Solidity is a boolean, either Solid or NotSolid. The Viscosity of Water, etc are handled separately. (see below).
  • A Solid object is basically anything which has Mass.
  • Physicsmode:
1 : Solid, pushes the player away.
2 : Non-solid, but gets pushed away by the player.
3 : Non-solid, clientside simulated only.
  • Volume : CollisionModel ...


  • Velocity
Velocity is a vector; it has both magnitude (speed) and direction. Velocity = Time * Acceleration / Mass.
Maximum Velocity of an object is achieved when the forces of acceleration and deceleration are balanced. Deceleration is usually caused by Friction, eg Air Resistance, Surface Friction.
  • Gravity accelerates objects at 32 ft/sec² (= 21.9 mph/sec)
  • Game variable (Gravity = 1 by default) seems to be applied equally to both VPhys and QPhys calculations ...
  • Todo:  does changing gravity affect trajectory of crossbow bolt, etc ?
  • Air Resistance or Aerodynamic Friction decelerates objects moving through Air.
  • Hull-objects use a simple "max speed" value for "flying", "running", etc. specified per Entity Class.
  • Freefalling Hull-objects use a worldconstant Terminal Velocity = 3500 units/sec (218.75 ft/sec) (ie reached after 6.8 sec of freefall).
  • VPhys-objects use
    Todo: ...?
    .
  • Wind Forces ...
  • Water Resistance or Hydrodynamic Friction decelerates objects moving through Water.
  • Hull-objects use a simple "max speed" value for "surface swim" and "underwater swim" (if they don't just drown) specified per Entity Class.
  • Sinking Hull-objects ... Player sinks at 48 units/sec (3 ft/sec)
    Todo:  check that NPCs sink at same speed ?
    .
  • VPhys-objects use
    Todo: ... ?
    .
  • Water is approx 50-100 times more viscous than air than air ... Newtonian Fluid?
  • Current Forces ...
  • Surface Friction between two parallel solid surfaces in contact = Perpendicular Pressure * Friction Coefficient:
  • Perpendicular Pressure : eg Object's on a Horizontal surface, Weight*Friction = resistance to sliding Horizontal movement.
  • Friction Coefficient is specific to each combination of surfaces; eg Rubber & Wood, Metal & Wood, Rubber & Metal, Rubber & Rubber, ... look-up table in Materials System ?
  • Sliding on Slope : where F = Friction Coefficient, object will slip on rise:run of 1:1/F or steeper. So if F = 1, slope = 1:1, if F = 0.5, slope = 1:2, etc
  • Sliding on Tilt Angle : where F = Friction Coefficient, and A = Angle of Elevation: F = tan A. So F 1 = 45°, F 0.5 = 26.6°, F 2 = 63.4°(calc)

Physics Consistency

Whilst the scientific field of Physics describes interactions between all physical phenomena (including the behaviour of light, sound, heat, etc), the Source Physics Engine(s) deal exclusively with Mechanical interactions between Solid objects in the World.

An important aspect of Source gameplay is that the physical interactions between World objects remains reasonably consistent and predictable. There would be no point in using a physical-mechanics simulation system that wasn't. (Actually, level designers frequently use physics as a "special effect" - so, given we are making games here [not scientific simulations], level designers should have more control over the implementation of physics in each given context.) For technical (legacy) and CPU performance optimisation reasons, not all World objects can be physically simulated to the same level of detail.

VPhysics is derived from the Havok Physics Engine, and determines the Linear and Angular Motion of VPhys Objects resulting from the interaction of various (simulated) VPhys Forces. It is a kind of Procedural Animation Engine designed to simulate Newtonian Mechanics. The Gravgun is a key part of the VPhys system, enhancing the Player's ability to influence VPhys Objects and events.

QPhysics (Likely stands for "Quake Physics") is not nearly as sophisticated as VPhys, but equally important as it is used in determining the Motion of all Hull-simulated NPCs and Players, several types of projectile and a number of Moving Brush Entities (eg func_door, etc).

The biggest difference is that VPhysics alone determines the motion and behaviour of Vphys Objects, whereas QPhysics merely imposes a few simple restrictions on objects that are primarily controlled by either Player Input, NPC AI, an I/O script, Scripted Animation Sequence, Entity Script, etc, etc.

Todo:  Where do these "physics interactions" fit in ?
  • Heat System : Flammable objects & fire spreading between them.
  • Damage System : Breakable objects, Falling & Impact Damage calculations
  • Gravgun Attack1 'knock-back' effect on Antlions, Manhacks, Scanners, etc

Projectiles

  • A VPhys object can be Pushed or Damaged by anything (solid) that hits it - Bullet, Hull, or other VPhys object.
  • A Bullet (ray) is so small and fast that nothing can Push or Damage it.
  • All explosions push and damage VPhys objects. Hulls may be damaged.
Projectile 	Gravity	Deflection	Impact Damage 	Solid Model 	NPC Push
bullet 		no 	no 		skill.cfg 	Ray 		no?
grenade-SMG 	yes 	no (explode) 	no? 		Hull? 		no?
crossbow bolt 	yes 	no (impale) 	skill.cfg 	Hull? 		no 
rocket 		no 	no (explode) 	no? 		Hull 		no?
NPC/Player 	yes 	no 		no? 		Hull 		yes
grenade-frag 	VPhys 	VPhys 		yes? 		VPhys 		yes?
grenade-AR2 	no ? 	VPhys 		yes? 		VPhys 		yes?
gravgun-prop 	VPhys 	VPhys 		yes? 		VPhys 		yes?
explosion 	no 	no 		no 		VPhys 		no
func_door 	no 	no? 		crush? 		Hull? 		yes?
  • Gravity : Will Gravity affect its Trajectory (Linear Motion).
  • Deflection : Will it bounce/ricochet off a solid object rather than simply stopping ? (Linear & Angular Motion)
  • Impact Damage : Will it inflict damage on collision (excluding explosion damage defined in skill.cfg).
Presumambly derived from Projectile's Momentum (kinetic energy): calculated or look-up table ?
Constraint is a static pull force; it resists movement away. ?
Impact Damage Table suggests vphys object mass is classed ("tiny, small, medium and large") relative to "Player, Player in Vehicle, NPC or Glass". Damage clamps & multipliers are specified for some classes, but the basic calculation ... ?
Prop Data#Damage Modifiers for "bullet, club, explosive" are only applied to breakable-props.
why should glass use a damage_table plus prop_data dam-mods ?
  • Solid Model : Physics interaction simulation system used.
  • NPC Push : Some collisions seem to affect (stop/slow/deflect) an NPC's Hull Momentum? Isn't there something like this in DOD? Hull Motion seems to be entirely immune to external (VPhys) forces unless specifically scripted otherwise - eg Combine_Soldier melee attack: Push back player ?. What about Rocket Jumping in TF2?
  • Todo:  Are Collision Hulls really boxes? They seem to behave more like Cylinders in game. Eg A Player should not be able to walk diagonally (W+A) along a 34 unit passageway, as the diagonal dimension of his 32x32 Hull would be 45 units. For that matter, he would not be able to rotate (much) either. Cylinders don't have corners to catch on things and cause rotational deflection. The test would be an octagonal hole ...

Hull QPhysics Interactions

  • Hull Translation and Rotation Motion : controlled by PlayerInput/AI/IO/WeaponScript/etc ...
nb: dynamic light, turret & camera entities can track a moving target<target_destination>.
  • Hull Gravity: eg Jump Trajectory. Alternative, separate Gravity system to VPhys ... ?
  • Hull Linear Deflection : Static Solids cause Hulls to simply stop moving. Deflection/Ricochet/Knock-Back is not simulated.
  • Hull Angular Deflection : vectors striking a hitbox but not passing through the CofMass do not induce rotation. Not simulated.
  • Hull Friction : There is definitely some kind of Player Hull friction simulation going on in 33 unit passageways.
Mud material reduces Player movements through it's own mechanism, not VPhys.
  • Hull Impact Damage : Fall Damage to Player/NPC. Impact Damage to breakable object he lands on.... Impact Damage Tables.
  • Physics Shadow: "If Players don't have a physics shadow they can't move objects just by touching them; they have to press USE to apply a pushing force" (from Alternate Multiplayer Physics).
    • compare physicsmode_choices per prop_phys_mp : "Solid, pushes player away" vs "Non-solid, but gets pushed away by the player".


Collision Event

  1. Collision Detection - if projectile touches target's Bounding Box :
    • If projectile = bullet, test against target's Hitbox and then CollisionProperty
    • If projectile = Hull or VPhys, test against target's CollisionModel ?
  2. Calculate Angular Force of Impact on both objects; ie
    • projectile's movement vector in relation to center of mass of target
    • projectile's movement vector in relation to center of mass of projectile
  3. Projectile Momentum absorbed by / transferred to:
    1. damage to target
    2. damage to projectile
    3. angular deflection (spin force) on target (unless t = Hull)
    4. angular deflection (spin force) on projectile (unless p = Hull)
    5. linear deflection (push vector) on target
    6. linear deflection (bounce vector) on projectile (unless p = Hull)


Mechanical Properties & Interactions

  • Qphys Collision Hull
Geometry & rigging = is bbox-defined in Entity Class (eg NPC Hull, Player Hull, projectile hulls?)
Player & NPC Hull always have "square" footprint. Player & some NPCs have multiple Hulls eg Player's DUCK_HULL and OBS_HULL.
Ground Hull: Origin = center of the base face; Flying Hull (centered hull) Origin = geometric center of box.
Qhull is not deflected by linear vphys forces. Solid obstacles simply block movement.
Qhull cannot rotate so not deflected by angular forces. Qhulls are always AABB to world axes - any Entity rotation is not applied to Qhull.
  • Vphys Collision Model (=IPhysicsObject?)
Geometry & Rigging is vertex-defined in Studiomodel.phy (or func_physbox)
Vphys hull rotation induces rotation of EntityOrigin or BoneOrigin.
Vphys forces act on Collisionmodel (Vphys hulls), causing the Entity to move and/or rotate.
Collision Model total Volume is calculated for $automass
Angular Momentum (ie spinning about Center of Mass) as opposed to Linear Momentum (ie linear velocity of Center of Mass)
By default: Center of mass/rotation is aligned to ModelOrigin and EntityOrigin = geometric center of bounding box.
  • Rotation : Settling / Stability
Gravity applies as Torque about the CofMass until CollModel (Fulcrum) provides stable support.
Collision Model might be translated into a collection of tetrahedra/tripods: Triangles relative to $CofMass?
so Rotational Stability = Triangular "foot" perpendicular to Center of Momentum vector.
  • Impact Damage & Vphys push (to both colliding objects): -- does damage absorb momentum?
Flex - ie ragdoll model
Break - ie breakable model
Explode -

Player & NPC Hulls

Hull Type               Hull-1 vectors                  Hull-2 vectors                  Hull-1 dimensions    Hull-2 dimensions

Ground Nav NPC (from ai_hull.cpp)
*  Tiny_Hull		(-12,-12,  0),	(12, 12,  24),	(-12,-12,  0),	(12, 12,  24) 	= 24 x 24 x 24	 ==   24 x 24 x 24 
*  Human_Hull		(-13,-13,  0),	(13, 13,  72),	( -8, -8,  0),	( 8,  8,  72) 	= 26 x 26 x 72	 &/   16 x 16 x 72 
*  Wide_Human_Hull	(-15,-15,  0),	(15, 15,  72),	(-10,-10,  0),	(10, 10,  72)  	= 30 x 30 x 72	 &/   20 x 20 x 72 
*  Medium_Hull		(-16,-16,  0),	(16, 16,  64),	( -8, -8,  0),	( 8,  8,  64) 	= 32 x 32 x 64	 &/   16 x 16 x 64
*  Medium_Tall_Hull	(-18,-18,  0),	(18, 18, 100),	(-12,-12,  0),	(12, 12, 100) 	= 36 x 36 x 100	 &/   24 x 24 x 100
*  Wide_Short_Hull	(-35,-35,  0),	(35, 35,  32),	(-20,-20,  0),	(20, 20,  32)   = 70 x 70 x 32	 &/   40 x 40 x 32
*  Large_Hull		(-40,-40,  0),	(40, 40, 100),	(-40,-40,  0),	(40, 40, 100) 	= 80 x 80 x 100	 ==   80 x 80 x 100

Air Nav NPC (from ai_hull.cpp)
*  Tiny_Centered_Hull	( -8, -8, -4),	( 8,  8,   4),	( -8, -8, -4),	( 8,  8,   4) 	= 16 x 16 x  8	 ==   16 x 16 x  8 
*  Small_Centered_Hull	(-20,-20,-20),	(20, 20,  20),	(-12,-12,-12),	(12, 12,  12) 	= 40 x 40 x 40	 &/   24 x 24 x 24 
*  Large_Centered_Hull	(-38,-38,-38),	(38, 38,  38),	(-30,-30,-30),	(30, 30,  30) 	= 76 x 76 x 76	 &/   60 x 60 x 60 

Player (from gamerules.cpp)
 * (normal)_HULL	(-16,-16,  0),	(16, 16,  72),	                         	= 32 x 32 x 72	 
 * DUCK_HULL	        (-16,-16,  0),	(16, 16,  36),	                         	= 32 x 32 x 36	 
 * OBS_HULL	        (-10,-10,-10),	(10, 10,  10),	                         	= 20 x 20 x 20	 

note: All Hulls have a square footprint with the origin in its centre.
note: Ground nav Hulls' $origin is at the base of the vertical axis, whereas Air-nav (_Centered_Hull) $origin is mid-vertical axis.
note: The mysterious NPC Hull-2 always fits inside Hull-1, and shares the same axes of symmetry as Hull-1.

Force Entities


Stub

This article or section is a stub. You can help by expanding it.