Physics Entities on Server & Client: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(spam (this is getting annoying...))
Line 1: Line 1:
[http://enlard.info/index1_500.html page] [http://libreriainciliegio.demogen.info/ libreria in ciliegio] [http://alessandraimperia.alient.info/ alessandra imperia] [http://noleggioautobrescia.behav.info/ noleggio auto brescia] [http://wwwmaxpezzali.wedged.info/ www maxpezzali com] [http://goroka.etotest.info/ goroka] [http://manualediseduzione.skains.info/ manuale di seduzione] [http://feetfetishclips.demogen.info/ feet fetish clips] [http://splav.alient.info/ splav] [http://cuoredizingaro.demogen.info/ cuore di zingaro] [http://logitechharmony.demogen.info/ logitech harmony 688] [http://cachando.enlard.info/ cachando] [http://sonyhifi51.alient.info/ sony hifi 5 1] [http://youdontownmedirty.skains.info/ you don t own me dirty dancing] [http://leggedisangue.demogen.info/ legge di sangue] [http://wedged.info/index7_1000.html link] [http://boxworld.skains.info/ boxworld] [http://riassuntolacoscienza.behav.info/ riassunto la coscienza di zeno] [http://laghiprofondi.etotest.info/ laghi profondi] [http://photoalbumdesigner.wedged.info/ photo album designer 133] [http://allacortedi.skains.info/ alla corte di bacco] [http://anydvdv3611.etotest.info/ anydvd v3 6 1 1] [http://horsecum.etotest.info/ horse cum] [http://seanpaulfeelalright.skains.info/ sean paul feel alright] [http://divxmp3telecomando.behav.info/ divx mp3 telecomando portatile] [http://finestrainfisso.etotest.info/ finestra infisso alluminio] [http://asuspm740.skains.info/ asus pm740] [http://hoteleconomico.behav.info/ hotel economico granada] [http://assorbentemessina.enlard.info/ assorbente messina] [http://behav.info/index6_500.html link] [http://mondialerally.skains.info/ mondiale rally] [http://didikhalid.wedged.info/ didi khalid] [http://ramperhpdc5100.alient.info/ ram per hp dc5100] [http://ognigiornodi.demogen.info/ ogni giorno di piu gazosa] [http://transmetacomputer.skains.info/ transmeta computer] [http://smuji.etotest.info/ smuji] [http://calendariomichelle.enlard.info/ calendario michelle hunzicher] [http://schedavideo.behav.info/ scheda video 128 mb] [http://orphen.behav.info/ orphen] [http://scandal.wedged.info/ scandal] [http://sexsoenvivo.skains.info/ sexso en vivo] [http://videoscambisti.demogen.info/ video scambisti] [http://ivicinidicasa.alient.info/ i vicini di casa] [http://suoneriesway.etotest.info/ suonerie sway] [http://indirizziinternet.skains.info/ indirizzi internet] [http://mosseerotiche.behav.info/ mosse erotiche] [http://magianuda.wedged.info/ magia nuda] [http://mikewhite.alient.info/ mike white] [http://simacga1000.alient.info/ simac ga 1000] [http://spalato.skains.info/ spalato] [http://lettorimp3wma.etotest.info/ lettori mp3 wma fm] [http://scopatedonnecon.behav.info/ scopate donne con animali] [http://etotest.info/index1_1000.html map] [http://olivettijp192.etotest.info/ olivetti jp 192] [http://sierrapittrivers.behav.info/ sierra pitt rivers] [http://letsego.wedged.info/ let s e go] [http://marronfivethis.alient.info/ marron five this love] [http://aereonauticadifesa.etotest.info/ aereonautica difesa it] [http://etotest.info/ etotest.info] [http://dittarea.etotest.info/ ditta rea] [http://federicazarrihard.enlard.info/ federica zarri hard] [http://orologifossilda.etotest.info/ orologi fossil da donna] [http://cappellini.demogen.info/ cappellini] [http://assicurazionepiombino.wedged.info/ assicurazione piombino] [http://bachariasullaquarta.demogen.info/ bach aria sulla quarta nota] [http://cavicaraudio.alient.info/ cavi car audio] [http://zenabezimena.wedged.info/ zena bez imena] [http://diffusoriinfinity.skains.info/ diffusori infinity 50] [http://abitic7schede.wedged.info/ abit ic7 schede madri] [http://wedged.info/index9_250.html site] [http://pokemontrucchi.wedged.info/ pokemon trucchi per gameboy] [http://dr2000.skains.info/ dr 2000] [http://chadkroegerhero.etotest.info/ chad kroeger hero] [http://geometrieebotanica.wedged.info/ geometrie e botanica libri] [http://dvd31.etotest.info/ dvd 31] [http://harddiskpermemory.behav.info/ hard disk per memory card] [http://sbloccoa835.etotest.info/ sblocco a835] [http://ilcolpodellametropolitana.etotest.info/ il colpo della metropolitana - un ostaggio al minuto] [http://restauroarchitettonico.behav.info/ restauro architettonico] [http://cannemozze.etotest.info/ canne mozze] [http://westcoastallstars.wedged.info/ west coast all stars] [http://automodellino.etotest.info/ auto modellino] [http://scanoboa.behav.info/ scano boa] [http://suburbiacompilation.wedged.info/ suburbia compilation 2004] [http://u2-thebestof1990-2000.enlard.info/ u2 - the best of 1990-2000] [http://bootrom.etotest.info/ boot rom] [http://piediconcalze.etotest.info/ piedi con calze nere sexy] [http://ericssonsuoneria.behav.info/ ericsson suoneria cellulare] [http://webdevelopment.enlard.info/ web development] [http://adslmichelangelo.skains.info/ adsl michelangelo pci] [http://jenny82.etotest.info/ jenny82] [http://libridimagiaeincantesimi.demogen.info/ libri di magia e incantesimi] [http://traveltorhodes.behav.info/ travel to rhodes] [http://rossellabrescia.etotest.info/ rossellabrescia] [http://convertitorifile.alient.info/ convertitori file wma mp3] [http://taglicapellicorti.wedged.info/ tagli capelli corti] [http://vogliovenire.wedged.info/ voglio venire] [http://prolocomoncalieri.demogen.info/ pro loco moncalieri] [http://donneperverse.alient.info/ donne perverse] [http://divxrete.skains.info/ divx rete]
[[Category:Programming]]
[[Category:Programming]]
=Overview=
=Overview=

Revision as of 02:38, 24 October 2007

Overview

A major feature of the Source Engine is the physical simulation of rigid bodies. This simulation implements mostly mechanical and Newtonian physics like gravity, trajectory, friction, collisions, springs and dampening. Models have to support this simulation by providing information about their collision model, material type, weight etc. In single player mode all physics entities are controlled and simulated by the server (server-side physics) and networked to the client. In multiplayer mode smaller objects like cans or bottles that doesn't affect gameplay are completely simulated client-side and are therefore not synchronized between clients. This is necessary because moving physics entities generate significant network traffic since they change their position and orientation basically with every frame. Networking these updates would almost stall any connection as soon as lots of physics object start to move at the same time (explosions, etc). Client-side physics objects don't affect player movement, and they should always be significantly smaller than players so that a player can not hide behind the objects. When destroying server-side breakable objects, they break apart into smaller client-side simulated fragments.

Adding physics entities

For a mapmaker it's pretty easy to place physics entities in Hammer. For single player maps the entity class physics_prop must be used to create server-side controlled physics entities. The player does correctly collide with these entities, can walk over them, push them around or pick them up. Unfortunately this class can't be used in multiplayer mode since player interaction with physics entities isn't predicted on the client and would cause jittery or delayed movement. Therefore a special entity class prop_physics_multiplayer must be used, which implements a simpler collision behavior (COLLISION_GROUP_PUSHAWAY). Multiplayer physics entities can only be pushed away, but not be used to walk over or picked up. If they are larger, a player just bounces off. Whether a multiplayer physics entity becomes a server-side or a client-side simulated entity, is defined by the object model.

The physical properties of a model are defined in it's .QC file by 3 entries: $surfaceprop, $collisionmodel, $keyvalues. The first entry $surfaceprop sets the model surface properties as defined in text file \scripts\surfaceproperties.txt. There properties like friction, elasticity and collision sounds are defined. The next entry $collisionmodel sets the collision model and the objects weight. The see collision models for entities in game enable console variable "vcollide_wireframe 1". The last section are the "prop_data" entries under $keyvalues. Here the object properties like health, break models and physics mode are defined (full description of prop_data). Here an example:

$surfaceprop "cardboard" // object surface properties

$collisionmodel "mymodel.smd" {
     $Mass 40	// Mass in kilograms
     $concave
}

$keyvalues
{
	"prop_data"
	{
		"base" 		"Cardboard.Medium" // base material defined in propdata.txt
		"health"		"40" // overriding material properties
		"physicsmode"	"1" // setting a custom physics mode
	}
}

The physics mode defines if the object becomes a server-side or client-side physics entity. There are to 2 server-side modes and one client-side mode define in props_shared.h:

#define PHYSICS_MULTIPLAYER_AUTODETECT	0	// autodetect mode based on mass & size
#define PHYSICS_MULTIPLAYER_SOLID		1	// server-side, solid (collides with player)
#define PHYSICS_MULTIPLAYER_NON_SOLID	2	// server-side, non-solid
#define PHYSICS_MULTIPLAYER_CLIENTSIDE	3	// client-side, non-solid>

If the physics mode property is not set in propdata.txt neither in the QC file, the physics mode will be picked by the function GetAutoMultiplayerPhysicsMode() based on the model's size and weight. A model will become a client-side physics entity, if it's size is below a certain threshold (set by console variable sv_pushaway_clientside_size).

Collision Groups

For quite some reason, it's not necessary that all dynamic physic entity collide with each other. That may be for game play reasons, but most of the time it's a performance issue. Especially creating dozens of small, fast moving debris pieces would drag down client performance significantly. As for the visual effect of breaking debris or exploding particle-like objects it's sufficient enough when they collide with static world objects, but not with themselves or other dynamic objects. To implement specific collision behavior the Source engine allows to define collision groups and specify if elements of these groups should collide or not. Each entity belongs to a single group at a time set with SetCollisionGroup(). New groups and new rules can be added easily. The physics subsystem queries the virtual function bool CGameRules::ShouldCollide(int group0, int group1) to see if a collision check must be run for between two objects. Already existing collision groups are:

COLLISION_GROUP_NONE Default, collsides with static and dynamic objects
COLLISION_GROUP_DEBRIS Collides with nothing but world and static stuff
COLLISION_GROUP_DEBRIS_TRIGGER Same as debris, but hits triggers
COLLISION_GROUP_INTERACTIVE_DEBRIS Collides with everything except other interactive debris or debris
COLLISION_GROUP_INTERACTIVE Collides with everything except interactive debris or debris
COLLISION_GROUP_PLAYER Collision group for player
COLLISION_GROUP_BREAKABLE_GLASS Special group for glass debris
COLLISION_GROUP_VEHICLE Collision group for driveable vehicles
COLLISION_GROUP_PLAYER_MOVEMENT For singleplayer, same as Collision_Group_Player, for multiplayer, this filters out other players and CBaseObjects
COLLISION_GROUP_NPC Generic NPC group
COLLISION_GROUP_IN_VEHICLE for any entity inside a vehicle
COLLISION_GROUP_WEAPON for any weapons that need collision detection
COLLISION_GROUP_VEHICLE_CLIP vehicle clip brush to restrict vehicle movement
COLLISION_GROUP_PROJECTILE Projectiles
COLLISION_GROUP_DOOR_BLOCKER Blocks entities not permitted to get near moving doors
COLLISION_GROUP_PASSABLE_DOOR Doors that the player shouldn't collide with
COLLISION_GROUP_DISSOLVING Things that are dissolving are in this group
COLLISION_GROUP_PUSHAWAY Nonsolid on client and server, pushs player away

Appendix

List of valid commands in the $collisionmodel section of a model:

$mass Manually set the mass of the model
$automass Tell the physics system to compute a mass for the model, based on it's surfaceprops & volume
$inertia Inertia scale
$damping Linear damping scale
$rotdamping Rotational damping scale
$drag Scales the air resistance
$concave The vphysics collision model is not a single convex hull. If not set, it'll make a single convex hull out of whatever geometry you give it.
$masscenter Override the center of mass, in local coords
$jointskip Rarely used. Eliminates a joint in the collision model that you don't want to use. (i.e. if you were using a render model as a ragdoll, and it has bones you don't want)
$jointmerge Merges the vertex assignments for two joints.
$rootbone The parent-most bone that actually has collision geometry.
$jointconstrain The limits of the joint's movement
$jointinertia Like $inertia, but per-bone
$jointdamping Like $damping, but per-bone
$jointrotdamping Like $rotdamping, but per-bone
$jointmassbias Mass is automatically distributed by volume, this lets you bias it per-bone
$noselfcollisions Turns off all collisions between bones in this model, usually for perf.
$jointcollide If any $jointcollide pairs are specified, only those joints collide with each other.
$animatedfriction Used to animate the amount of friction on joints over time.

List of valid entries for propdata.txt definitions:

base Specify a base propdata class to derive from (base types can be found in propdata.txt)
blockLOS Override whether this prop should block NPC's Line-Of-Sight.
AIWalkable Override whether AI should consider this prop as walkable on.
dmg.bullets Mod damage done by bullets to this prop.
dmg.club Mod damage done by clubs to this prop.
dmg.explosive Mod damage done by explosives to this prop.
health Amount of damage this prop should take before breaking.
explosive_damage Explosive damage done by this prop.
explosive_radius Radius of the explosion caused by this prop when it breaks.
breakable_model The type of breakable gibs this prop should break into
breakable_count The number of breakable gibs to break into.
allowstatic Allow this prop to be static as well as physically simulated.
physicsmode Set multiplayer physics behavior (1=full, 2=non-solid,3=clientside)