Skip to main content

PfxLayer

PfxLayer holds the game's physics collision layers. Every physics body is in one layer, and a raycast is done with a filter layer that decides which bodies it can hit. Use it to pick what Physics.Raycast sees: only the static world, everything physical, only vehicles, and so on.

Available on: Client

Values​

PfxLayer​

Used by Physics.Raycast(from, to, layer) (client): the ray hits what layer collides with. The value is passed to the game without checking it.

The layers a raycast is usually done with are the query layers near the end of the table: RaycastDefault for ordinary line-of-sight checks, RaycastEverythingPhysical to hit anything solid, StaticAndDestruction for the world only, and AllDynamicObjects for moving things only. The body layers (the first ones) describe what a body is; a ray cast with one of them hits what that kind of body collides with.

NameValueMeaning
PfxLayer.FullCollision0Collides with everything.
PfxLayer.NoCollision1Collides with nothing except FullCollision.
PfxLayer.Static2Standard static objects (buildings, rocks, props that never move).
PfxLayer.Terrain3The terrain (heightfield).
PfxLayer.Dynamic4Standard dynamic objects (things physics moves around).
PfxLayer.Destruction5Destructible objects.
PfxLayer.CharacterCollision6The character capsule (the body that walks around).
PfxLayer.CharacterGhostMode7The character capsule while the character is in ghost mode.
PfxLayer.CharacterRagdoll8Ragdoll bodies that physics simulates.
PfxLayer.CharacterRagdollKeyframed9Ragdoll bodies that follow the animation.
PfxLayer.CharacterAttachedDynamicRb10Rigid bodies characters are attached to.
PfxLayer.CharacterRagdollProxies11The simplified ragdoll shapes used for aiming and shooting at characters.
PfxLayer.Particle12Physical particles.
PfxLayer.Explosive13Physical explosives, like grenades.
PfxLayer.Projectile14Physical projectiles, like missiles.
PfxLayer.Weapons15Weapons lying around in the world.
PfxLayer.VehicleCollisionWheel16Vehicle wheels.
PfxLayer.VehicleCollisionDynamicOnly17Vehicle bodies that only collide with other dynamic bodies.
PfxLayer.VehicleCollision18Vehicle bodies.
PfxLayer.VehicleRaycast19The vehicle raycast shape.
PfxLayer.RaycastDefault20Query layer: regular raycasts.
PfxLayer.RaycastEverythingPhysical21Query layer: hits everything physical.
PfxLayer.RaycastWheels22Query layer: hits everything physical, as used by wheels.
PfxLayer.ShapeQueryDefault23Query layer: default volume checks.
PfxLayer.ShapeQueryTrigger24Query layer: volume triggers.
PfxLayer.ShapeQueryExplosion25Query layer: explosion volumes.
PfxLayer.ShapeQueryVehicles26Query layer: vehicle volumes.
PfxLayer.StaticAndDestruction27Query layer: static objects, terrain and destructible objects.
PfxLayer.AllDynamicObjects28Query layer: every dynamic object.
PfxLayer.ListenerEffects29Query layer: low quality vehicles, terrain and rigid objects (used for audio listener effects).
PfxLayer.ShapeQueryClimbing30Query layer: things the player can climb on.

Example

-- client: what is the local player aiming at? check the static world first, then anything physical
Cmd.Add("look", function()
local player = World.LocalPlayer():AsPlayer()
local from = Camera.GetPosition()
local to = player:GetAimPosition()
local dir = (to - from):normalize()
local far = from + dir * 500

local world_hit = Physics.Raycast(from, far, PfxLayer.StaticAndDestruction)
if world_hit.hasHit then
print(string.format("world at %.1f m", world_hit.hitDistance * 500))
end

local any_hit = Physics.Raycast(from, far, PfxLayer.RaycastEverythingPhysical)
if any_hit.hasHit and any_hit.netObject then
print("aiming at a networked object of type " .. any_hit.netObject:GetType())
end
end)