Ss14 physics system api

From space-sunrise/project-fire · View interactive version

Ss14 physics system api is an AI agent skill from the GitHub repository space-sunrise/project-fire. A complete reference to the SharedPhysicsSystem public API in Space Station 14: all method families, overloads, limitations, rare methods and practical examples of use on the server and client. Use it when you need to accurately select the PhysicsSystem method and not break contacts/collisions/predi

How to use this skill

Skill file

PhysicsSystem: API

This skill is the public API directory SharedPhysicsSystem :)

For the general architecture, first read SS14 Physics System Core.

How to use this directory

  1. First select the task type:
  1. Then select the level:
  1. If fixtures/collisions have changed:

1) Runtime and world level

Public runtime fields/state:

When to use:

2) Impulses and forces

Nuance:

3) Body dynamics and condition

3.1 Speeds, damping, weight

3.2 Awake/sleep/prediction

3.3 Body mode and collision

Critical:

4) Speeds in map terms

When to use:

5) Fixtures: material and collision profile

Practice:

5.1) CollisionGroup: full map of layers/masks :)

Rule of Contact (Source of Truth)

Two fixtures are considered to be in contact if at least one condition is met:

That is, this is not strict two-way filtering, but the logic “at least one side wants contact.”

// Basic contact check of a pair of fixtures.
var shouldCollide =
    (fixtureA.CollisionMask & fixtureB.CollisionLayer) != 0 ||
    (fixtureB.CollisionMask & fixtureA.CollisionLayer) != 0;

Important:

Matrix of basic layer/mask bits (all basic flags)

✓ - the layer will be caught by this mask, · - it will not.

| layer \ mask | Opaque | Impassable | MidImpassable | HighImpassable | LowImpassable | GhostImpassable | BulletImpassable | InteractImpassable | DoorPassable |

|---|---|---|---|---|---|---|---|---|---|

| Opaque | ✓ | · | · | · | · | · | · | · | · |

| Impassable | · | ✓ | · | · | · | · | · | · | · |

| MidImpassable | · | · | ✓ | · | · | · | · | · | · |

| HighImpassable | · | · | · | ✓ | · | · | · | · | · |

| LowImpassable | · | · | · | · | ✓ | · | · | · | · |

| GhostImpassable | · | · | · | · | · | ✓ | · | · | · |

| BulletImpassable | · | · | · | · | · | · | ✓ | · | · |

| InteractImpassable | · | · | · | · | · | · | · | ✓ | · |

| DoorPassable | · | · | · | · | · | · | · | · | ✓ |

Ready-made CollisionGroups: what they are and who to issue them to

The Who to grant to column describes a practical intent (a typical content profile), and not a hard and fast rule.

| Group | Use as | Composition | To whom to issue |

|---|---|---|---|

| None | layer/mask | 0 | temporarily disabled filter, service cases |

| Opaque | layer | base bit | objects that block light/part of the rays |

| Impassable | layer/mask bit | base bit | full-fledged obstacles on the ground |

| MidImpassable | layer/mask bit | base bit | "medium height": mobs, racks, some furniture |

| HighImpassable | layer/mask bit | base bit | top of obstacles (tables, high blockers) |

| LowImpassable | layer/mask bit | base bit | low obstacles important for small/under-table logic |

| GhostImpassable | layer/mask bit | base bit | Ghost/Watcher Blockers |

| BulletImpassable | layer/mask bit | base bit | everything that should stop bullets |

| InteractImpassable | layer/mask bit | base bit | lock InRangeUnobstructed/interaction |

| DoorPassable | layer/mask bit | base bit | special "door-passable" surfaces |

| MapGrid | layer | map/grid specialbit | grid system layer |

| AllMask | mask | -1 | rare force cases (almost always redundant) |

| SingularityLayer | layer+mask | Opaque+Impassable+Mid+High+Low+Bullet+Interact+DoorPassable | singularity/similar "all-consuming" entities |

| MobMask | mask | Impassable+High+Mid+Low | humanoids/regular ground mobs |

| MobLayer | layer | Opaque+BulletImpassable | base layer of normal mobs |

| SmallMobMask | mask | Impassable+Low | small mobs (mice, etc.) |

| SmallMobLayer | layer | Opaque+BulletImpassable | small mobs layer |

| FlyingMobMask | mask | Impassable+High | small flying entities |

| FlyingMobLayer | layer | Opaque+BulletImpassable | flying mobs layer |

| LargeMobMask | mask | Impassable+High+Mid+Low | large entities/vehicles/mechs |

| LargeMobLayer | layer | Opaque+High+Mid+Low+BulletImpassable | large objects that "take up" more height |

| MachineMask | mask | Impassable+Mid+Low | large machines/stationary structures |

| MachineLayer | layer | Opaque+Mid+Low+BulletImpassable | machines, automatic machines, frames |

| ConveyorMask | layer or mask in place | Impassable+Mid+Low+DoorPassable | conveyors and door compatibility |

| CrateMask | mask | Impassable+High+Low | containers/cages that require "low traffic" under flaps |

| TableMask | mask | Impassable+Mid | tables/surfaces with which other tables must interact |

| TableLayer | layer | MidImpassable | tables, railings, part of narrow barriers |

| TabletopMachineMask | mask | Impassable+High | desktop machines/windows |

| TabletopMachineLayer | layer | Opaque+BulletImpassable | small desktop devices |

| GlassAirlockLayer | layer | High+Mid+Bullet+Interact | glass airlock/window profiles |

| AirlockLayer | layer | Opaque+GlassAirlockLayer | regular airlock profiles |

| HumanoidBlockLayer | layer | High+Mid | assemblies/intermediate "human blocks" |

| SlipLayer | layer | Mid+Low | non-hard slip/puddle/trap triggers |

| ItemMask | mask | Impassable+High | objects, grenades, small props |

| ThrownItem | layer | Impassable+High+Bullet | special throw profiles (rare point case) |

| WallLayer | layer | Opaque+Impassable+High+Mid+Low+Bullet+Interact | full walls/barriers |

| GlassLayer | layer | Impassable+High+Mid+Low+Bullet+Interact | windows/glass obstacles |

| HalfWallLayer | layer | Mid+Low | "semi-high" obstacles |

| FlimsyLayer | layer | Opaque+High+Mid+Low+Interact | "fragile" walls that should not catch bullets like wall |

| SpecialWallLayer | layer+mask | Opaque+High+Mid+Low+Bullet | force-wall type: blocks movement/bullets, but does not block interact the same way as WallLayer |

| FullTileMask | mask | Impassable+High+Mid+Low+Interact | full tile blocker (walls, windows, doors, memorials, etc.) |

| FullTileLayer | layer | Opaque+High+Mid+Low+Bullet+Interact | rare non-hard/full-tile sensors and special fixtures |

| SubfloorMask | mask | Impassable+Low | underground/pipes/underground networks |

Quick delivery templates (from current configs)

Who contacts whom: matrix of typical profiles

✓ - contact is possible via layer/mask, · - no.

For Airlock the standard profile is adopted here: layer = AirlockLayer, mask = FullTileMask.

For Item and SubfloorPipe the common case with null layer is accepted.

| Profile | Mob | SmallMob | FlyingMob | Machine | Table | Airlock | Wall | Item | SlipTrigger(non-hard) | SubfloorPipe |

|---|---|---|---|---|---|---|---|---|---|---|

| Mob | · | · | · | ✓ | ✓ | ✓ | ✓ | · | ✓ | · |

| SmallMob | · | · | · | ✓ | · | · | ✓ | · | ✓ | · |

| FlyingMob | · | · | · | · | · | ✓ | ✓ | · | · | · |

| Machine | ✓ | ✓ | · | ✓ | ✓ | ✓ | ✓ | · | ✓ | ✓ |

| Table | ✓ | · | · | ✓ | ✓ | ✓ | ✓ | · | ✓ | · |

| Airlock | ✓ | · | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · |

| Wall | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |

| Item | · | · | · | · | · | ✓ | ✓ | · | · | · |

| SlipTrigger(non-hard) | ✓ | ✓ | · | ✓ | ✓ | ✓ | ✓ | · | · | ✓ |

| SubfloorPipe | · | · | · | ✓ | · | · | ✓ | · | ✓ | · |

Patterns for setting up collision

Anti-patterns collision settings

Example configurations

# Typical mob: standard ground collision.
fixtures:
  fix1:
    shape: !type:PhysShapeCircle { radius: 0.35 }
    mask: [MobMask]
    layer: [MobLayer]
# Full Tile Blocker (Wall): Blocks passage, interactions, and bullets.
fixtures:
  fix1:
    shape: !type:PhysShapeAabb { bounds: "-0.5,-0.5,0.5,0.5" }
    mask: [FullTileMask]
    layer: [WallLayer]
# Sliding trap: not hard, but gives a contact event based on the required mask.
fixtures:
  floortrap:
    hard: false
    shape: !type:PhysShapeAabb { bounds: "-0.4,-0.4,0.4,0.4" }
    mask: [ItemMask]
    layer: [SlipLayer]

6) Shapes API (fixture geometry)

7) Contacts and contact selections

ContactEnumerator:

8) Transformations of physics and bounds

9) Spatial query and ray API

10) Physics step events (useful for controllers)

Usage:

11) API selection patterns :)

12) Anti-patterns

13) Examples from code

Example 1: shuttle/motor via power and sleep

if (finalForce.Length() > 0f)
    PhysicsSystem.ApplyForce(shuttleUid, finalForce, body: body);

// Without entering, sleep can be allowed so as not to keep the body “eternally angry.”
PhysicsSystem.SetSleepingAllowed(shuttleUid, body, true);

Example 2: contact iterator as a "who's nearby" source

var contacts = PhysicsSystem.GetContacts(conveyorUid);
while (contacts.MoveNext(out var contact))
{
    var other = contact.OtherEnt(conveyorUid);
    PhysicsSystem.WakeBody(other);
}

Example 3: re-check contacts after changing physical mode

_physics.SetBodyType(uid, BodyType.Dynamic, fixtures, body, xform);
_physics.SetCanCollide(uid, true, manager: fixtures, body: body);
_broadphase.RegenerateContacts((uid, body, fixtures, xform));

Example 4: nearest-query for fair geometric distance

if (!_physics.TryGetNearest(uidA, uidB, out var pointA, out var pointB, out var distance, xfA, xfB))
    return;

if (distance <= interactionRange)
{
    // Objects are actually within the radius, taking into account the shapes of the fixtures.
}

Example 5: runtime switching "in the air" with sleep prohibition

_physics.SetBodyStatus(target, targetPhysics, BodyStatus.InAir, false);
_physics.SetSleepingAllowed(target, targetPhysics, false);
_physics.WakeBody(target, body: targetPhysics);

Example 6: point raycast with entity filter

var ray = new CollisionRay(origin, direction, mask);
var results = _physics.IntersectRayWithPredicate(
    mapId,
    ray,
    maxDistance,
    uid => uid == source || uid == ignored,
    returnOnFirstHit: false);

Example 7: mass scale of physical forms via system API

// Used for consistent visual and physics scaling.
_physics.ScaleFixtures(entity, factor);

Example 8: Selecting local physics-transform (not just local transform)

// For some intersection checks, the physics-space of the current broadphase is needed.
var physXf = PhysicsSystem.GetLocalPhysicsTransform(uid);

14) Mini-checklist before calling the method

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.