Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl/llms.txt

Use this file to discover all available pages before exploring further.

Prowl’s physics system is powered by Jitter2, a high-performance rigid-body simulation library for .NET. The static Physics class wraps Jitter2’s World object and exposes it through a Prowl-idiomatic API: raycasting with optional max-distance and layer-mask filtering, a symmetric layer collision matrix for controlling which game-object layers interact, and a PhysicsSetting singleton that is serialised as a project setting. The physics step is advanced each frame by Physics.Update(), which accumulates time and fires fixed-timestep substeps to keep the simulation stable regardless of frame rate.

Physics.World

public static World World { get; }
The underlying Jitter2 World instance. Lazily created on first access with a LayerFilter broad-phase filter that checks the layer collision matrix before running narrow-phase tests. Use this property when you need direct Jitter2 API access (e.g., adding constraints, querying contact manifolds).
Do not call World.Step() manually. Use Physics.Update() so the engine’s fixed-timestep accumulator is respected.

Physics.Update

public static void Update()
Advances the physics simulation. Internally:
  1. Accumulates Time.deltaTime into an internal timer.
  2. Fires up to 10 fixed-timestep substeps while the timer exceeds Time.fixedDeltaTime.
  3. Before each step, applies PhysicsSetting values (SolverIterations, RelaxIterations, Substep, AllowSleep, Gravity) to the World.
  4. If PhysicsSetting.UseMultithreading is true, Jitter2 parallelises the substep across available CPU cores.
  5. Calls SceneManager.PhysicsUpdate() each substep so scripts can run FixedUpdate logic.

Raycasting

All raycast overloads return true if the ray hit a collider and false otherwise. The direction parameter is normalised internally before the cast.

Overloads

public static bool Raycast(Vector3 origin, Vector3 direction)
Returns true if any collider is hit. No hit information is returned.

Parameters common to all overloads

origin
Vector3
World-space start point of the ray.
direction
Vector3
World-space direction. Normalised internally before casting.
maxDistance
double
Maximum distance to consider hits. Hits beyond this distance are ignored.
layerMask
LayerMask
Bit mask of layer indices to include. Only colliders on included layers are tested.
hitInfo
out RaycastHit
Populated with hit data when the cast returns true.
// Simple hit test
if (Physics.Raycast(transform.position, transform.forward))
    Debug.Log("Hit something!");

// Full hit info
if (Physics.Raycast(transform.position, transform.forward, out RaycastHit hit))
{
    Debug.Log($"Hit {hit.rigidbody?.GameObject?.Name} at {hit.point}, distance: {hit.distance:F2}");
}

// Layer-masked raycast
LayerMask enemies = LayerMask.FromNames("Enemy", "Boss");
if (Physics.Raycast(origin, direction, out RaycastHit h, 50.0, enemies))
    h.rigidbody.ApplyImpulse(direction * 10);

RaycastHit

RaycastHit is a value type (struct) that carries all information about a single physics ray intersection.
hit
bool
Whether the ray actually intersected something. This is true when the struct has been filled by a successful cast.
distance
double
Distance from origin to the impact point (Lambda from Jitter2’s result).
point
Vector3
World-space position of the impact point, computed as origin + direction * distance.
normal
Vector3
World-space surface normal at the hit point.
rigidbody
Rigidbody3D
The Rigidbody3D component attached to the struck object. May be null if the shape has no user data.
shape
RigidBodyShape
The specific Jitter2 RigidBodyShape that was hit, useful for sub-mesh or compound-shape identification.
transform
Transform
The Transform of the hit rigidbody’s GameObject. Shorthand for rigidbody?.GameObject?.Transform.

Layer Collision Matrix

The collision matrix controls which pairs of layers are allowed to generate contacts. It is stored symmetrically — enabling (layer1, layer2) automatically enables (layer2, layer1).

SetLayerCollision

public static void SetLayerCollision(int layer1Index, int layer2Index, bool shouldCollide)
Sets whether two specific layers should collide.
layer1Index
int
First layer index (0-based).
layer2Index
int
Second layer index (0-based).
shouldCollide
bool
Whether physics contacts should be generated between these layers.

GetLayerCollision

public static bool GetLayerCollision(int layer1, int layer2)
Returns true if the two layers are set to collide.

SetLayerCollisions

public static void SetLayerCollisions(int layer, bool shouldCollide)
Sets all entries in a given layer’s row and column — effectively enabling or disabling collisions between that layer and every other layer.

GetLayerCollisions

public static bool[] GetLayerCollisions(int layer)
Returns the full collision row for layer as a bool array.

SetAllCollisions

public static void SetAllCollisions(bool shouldCollide)
Sets every entry in the collision matrix to shouldCollide.

EnsureSymmetric

public static void EnsureSymmetric()
Rebuilds the matrix to ensure symmetry after any manual edits to PhysicsSetting.s_collisionMatrix.
// Prevent players from colliding with triggers
Physics.SetLayerCollision(LayerIndex.Player, LayerIndex.Trigger, false);

// Check if two layers collide
bool collides = Physics.GetLayerCollision(LayerIndex.Enemy, LayerIndex.Bullet);

PhysicsSetting

PhysicsSetting is a ScriptableSingleton<PhysicsSetting> serialised to PhysicsSettings.projsetting. Access it via PhysicsSetting.Instance.
Gravity
Vector3
World gravity vector. Default: (0, -9.81, 0).
SolverIterations
int
Number of velocity constraint solver iterations per substep. Range [1, 16]. Default: 6.
RelaxIterations
int
Number of position correction (relaxation) iterations. Range [0, 16]. Default: 4.
Substep
int
Number of Jitter2 substeps per fixed-timestep tick. Range [1, 16]. Default: 1.
TargetFrameRate
int
Fixed-timestep target in Hz. Determines Time.fixedDeltaTime = 1.0 / TargetFrameRate. Range [5, 120]. Default: 50.
AllowSleep
bool
Whether Jitter2 may deactivate sleeping rigid bodies for performance. Default: true.
UseMultithreading
bool
Whether Jitter2 parallelises the substep across CPU threads. Default: true.
AutoSyncTransforms
bool
When true, Rigidbody3D components automatically write simulation results back to Transform after each step.
s_collisionMatrix
Boolean32Matrix
The raw 32×32 symmetric collision matrix. Prefer the Physics.SetLayerCollision API over direct access.

Physics.Clear

[OnAssemblyLoad, OnAssemblyUnload, OnSceneLoad, OnSceneUnload, OnPlaymodeChanged]
public static void Clear()
Calls World.Clear() to remove all rigid bodies and shapes. Invoked automatically on scene load/unload and playmode transitions.

Build docs developers (and LLMs) love