Gravity

From Valve Developer Community
Jump to: navigation, search

Gravity in Source is measured in units/second2. The value is defined by sv_gravity, which defaults to 600 in Half-Life 2 (and episodes), Portal, and Portal 2. Default gravity is 800 in Valve's other games.

C++ functions

VPhysics

void physenv->SetGravity(Vector &gravityVector)
Sets the direction and strength of gravity for the VPhysics environment, which can be changed at any time independently of sv_gravity. Physics objects will sleep on the 'floor' no matter which direction it is in, but they will not wake of their own accord if gravity changes.
Tip.pngTip:Z should be negative for downward pull.
Note.pngNote:Changes must be manually networked to the client.
void IPhysicsObject::EnableGravity(bool enable)
Controls per-entity zero gravity. The object will tumble through the air if pushed.
Todo: Is there a way to set a gravity multiplier?

QPhysics

void CBaseEntity::PhysicsAddGravityMove(Vector &move)
Uses sv_gravity to add gravity to falling QPhysics entities (
Todo: including NPCs?
).
void CGameMovement::AddGravity()
As above, but for players.
void CBaseEntity::SetGravity(float gravity)
Sets a per-entity multiplier for QPhysics gravity. Default is 0, which should be considered 1.
Tip.pngTip:The Hammer keyvalue gravity can be used to add a gravity multiplier to individual QPhysics entities (which more or less means NPCs these days) without any new code. It isn't in the FGD so turn off SmartEdit and add it manually.

See also