Krotox Engine › Docs › Krotox Manual › 2D Physics

2D physics: bodies, colliders & world settings

How Box2D 3.x physics works in Krotox: body types, every collider shape, materials, triggers, collision layers and groups, fast-moving objects, effectors, the platformer character controller and the project's physics settings.

Krotox simulates 2D physics with Box2D 3.x. An entity takes part in physics when it has a Rigidbody 2D (how it moves) and at least one collider (its shape). This page covers setting them up in the editor. To control physics from code, see Rigidbody2D, colliders & collision callbacks.

Rigidbody 2D

FieldDefaultMeaning
TypeStaticStatic: never moves (ground, walls). Dynamic: moved by gravity, forces and collisions (players, crates, balls). Kinematic: moved only by your script's velocity, unaffected by forces (moving platforms, elevators).
Fixed RotationoffStops the body rotating. Turn it on for characters so they do not tip over.
Auto MassonWork out mass from the colliders' area and density.
Mass1Mass in kilograms when Auto Mass is off.
Center Of Mass0, 0Offset of the centre of mass.
Gravity Scale1Multiplies gravity for this body. 0 for top-down games and floating objects.
Bullet (CCD)offContinuous collision detection: sweeps the body between steps so it cannot pass through thin walls. For fast projectiles.
InterpolationInterpolateHow the drawn position blends between physics steps: None, Interpolate (smooth, slightly behind) or Extrapolate.
Collision Group0Box2D group index for every collider on the body. See Collision groups.
Sleep EnabledonLet the body sleep when it comes to rest.
To move a character, set its velocity or apply forces and impulses from a script. Writing the Transform of a Dynamic body fights the simulation. To teleport a body, set Rigidbody2DComponent.Position.

Colliders

ColliderShape fieldsUse it for
Box Collider 2DSize, OffsetCrates, platforms, simple characters.
Circle Collider 2DRadius, OffsetBalls, coins, round enemies.
Capsule Collider 2DRadius, Height (end to end), OffsetCharacters: the rounded bottom slides over bumps instead of catching.
Polygon Collider 2DVertices (convex, 3 to 8 points), OffsetIrregular convex shapes.
Segment Collider 2DPoint 0, Point 1A single line, such as a thin ledge.
Chain Collider 2DVertices (2 or more), LoopTerrain outlines and level boundaries.
Tilemap Collider 2D + Composite Collider 2D—Collision generated from painted tiles. See Tilemaps.

An entity can carry several colliders, and colliders on child entities belong to the parent's Rigidbody 2D. Build compound shapes that way: a body with a box for the torso and circles for the wheels.

Material and filtering fields

Every collider also has:

FieldDefaultMeaning
Density1Used for auto mass (not on Chain colliders).
Friction0.50 is ice, 1 is very grippy.
Restitution0Bounciness. 0 does not bounce, 1 bounces back with full energy.
Is SensoroffTrigger mode: reports overlaps but does not physically collide.
Use Layer Collision MatrixonFilter with the project's named layers.
Category Bits / Mask Bits0x0001 / allManual filtering bit masks.

Triggers

Turn on Is Sensor to make a collider a trigger: pickups, checkpoints, damage zones, doors that open when the player is near. Triggers report Enter, Stay and Exit to scripts (OnTriggerEnter, OnTriggerStay, OnTriggerExit) but never push anything.

For a trigger to fire, both entities need colliders and at least one of them needs a Rigidbody 2D.

Collision layers

Projects define up to 32 named physics layers in Project Settings, and a collision matrix says which layers collide. Put each entity on a layer (Layer in scripts) and untick the pairs that should pass through each other: the player and their own bullets, pickups and enemies, and so on.

Two colliders collide only if each one's category is in the other's mask:

collide = (CategoryA & MaskB) != 0  AND  (CategoryB & MaskA) != 0

Collision groups (for ragdolls)

Collision Group on the Rigidbody 2D overrides layers for bodies in the same group:

Give every limb of a ragdoll the same negative number and the limbs ignore each other while still hitting the world. No per-pair setup is needed.

Fast-moving objects

A body moving far enough in one step can skip past a thin collider ("tunnelling"). To prevent it:

  1. Turn on Bullet (CCD) on the fast body.
  2. Make thin walls a little thicker.
  3. If needed, raise the Physics Rate (below).

Max Linear Speed caps how fast any body may go.

Effectors

Effectors push bodies around without scripts. Most need a sensor collider on the same entity; they act on bodies inside it.

EffectorWhat it doesKey fields
Platform Effector 2DOne-way platforms you can jump up through and land on.Use One Way, Surface Arc (for example 180° for top-only), Surface Normal, Rotational Offset.
Area Effector 2DWind, currents, conveyor zones.Force Magnitude, Force Angle (0 = right, 90 = up), Force Variation (gusts), Mode (Additive or Target Velocity), Drag, Angular Drag.
Point Effector 2DAttracts or repels from a point: magnets, black holes, explosions.Force Magnitude (positive attracts, negative repels), Falloff (Constant, Linear, Inverse Square). Without a sensor collider it covers the whole scene.
Buoyancy Effector 2DWater: floating, drag and currents.Density, Surface Level, Linear Drag, Angular Drag, Flow Velocity.
Constant Force 2DA constant push or spin every step (rockets, thrusters).Force (world), Relative Force (body-relative), Torque.

Character Controller 2D

A ready-made platformer controller. It drives the entity's Rigidbody 2D (Dynamic, usually with Fixed Rotation) and adds ground detection and movement.

FieldMeaning
Move Speed, Jump ForceHorizontal speed and jump strength.
Max Slope AngleSteeper slopes push the character down and block walking uphill.
Ground Check Distance, Skin Width, Ground Layer MaskHow the ground is detected (rays from just inside the bottom of the collider).
Enable Gravity, Gravity ScaleGravity on the body.
Stick To GroundKeeps the character on the surface when walking down slopes, so "grounded" does not flicker.

From a script, call Walk(direction) every fixed update and Jump() when the player presses jump; read IsGrounded. See the scripting page.

Project physics settings

Project Settings ▸ Physics (Box2D). Changes take effect the next time you press Play.

SettingDefaultWhat it does
Gravity—World gravity.
Physics Rate (Hz)60Fixed steps per second (30–240). 120 or 240 reduces jitter in fast or tightly jointed bodies, at more CPU cost.
Sub Steps4Solver passes inside each step. More makes joints and stacks stiffer.
Contact Hertz / Damping / Speed30 / 10 / 3How firmly overlapping bodies are pushed apart, how damped that is, and the maximum push-out speed (m/s).
Restitution Threshold1 m/sImpacts slower than this do not bounce. This is world-wide; Box2D 3.x does not use a per-collider value.
Hit Event Threshold1 m/sImpacts faster than this raise hit events.
Enable SleeponResting bodies stop simulating until something wakes them.
Contact SofteningoffSoftens contacts between very light and very heavy bodies, so a light limb is not shoved around.
Max Linear Speed400 m/sHard speed cap.

How the simulation is timed

Physics runs on a fixed clock, independent of the frame rate. Each frame, the elapsed time goes into an accumulator, and the world steps as many times as fits (0, 1 or more). OnFixedUpdate() runs before each step.

Debugging physics

Joints, ragdolls and the physics gameplay components (bumpers, portals, conveyors and more) are on the next page: 2D joints, ragdolls & gameplay components.