Krotox Engine › Docs › Krotox Manual › 2D Physics
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.
| Field | Default | Meaning |
|---|---|---|
Type | Static | Static: 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 Rotation | off | Stops the body rotating. Turn it on for characters so they do not tip over. |
Auto Mass | on | Work out mass from the colliders' area and density. |
Mass | 1 | Mass in kilograms when Auto Mass is off. |
Center Of Mass | 0, 0 | Offset of the centre of mass. |
Gravity Scale | 1 | Multiplies gravity for this body. 0 for top-down games and floating objects. |
Bullet (CCD) | off | Continuous collision detection: sweeps the body between steps so it cannot pass through thin walls. For fast projectiles. |
Interpolation | Interpolate | How the drawn position blends between physics steps: None, Interpolate (smooth, slightly behind) or Extrapolate. |
Collision Group | 0 | Box2D group index for every collider on the body. See Collision groups. |
Sleep Enabled | on | Let 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.
| Collider | Shape fields | Use it for |
|---|---|---|
| Box Collider 2D | Size, Offset | Crates, platforms, simple characters. |
| Circle Collider 2D | Radius, Offset | Balls, coins, round enemies. |
| Capsule Collider 2D | Radius, Height (end to end), Offset | Characters: the rounded bottom slides over bumps instead of catching. |
| Polygon Collider 2D | Vertices (convex, 3 to 8 points), Offset | Irregular convex shapes. |
| Segment Collider 2D | Point 0, Point 1 | A single line, such as a thin ledge. |
| Chain Collider 2D | Vertices (2 or more), Loop | Terrain 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.
Every collider also has:
| Field | Default | Meaning |
|---|---|---|
Density | 1 | Used for auto mass (not on Chain colliders). |
Friction | 0.5 | 0 is ice, 1 is very grippy. |
Restitution | 0 | Bounciness. 0 does not bounce, 1 bounces back with full energy. |
Is Sensor | off | Trigger mode: reports overlaps but does not physically collide. |
Use Layer Collision Matrix | on | Filter with the project's named layers. |
Category Bits / Mask Bits | 0x0001 / all | Manual filtering bit masks. |
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.
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 Group on the Rigidbody 2D overrides layers for bodies in the same group:
0 means no 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.
A body moving far enough in one step can skip past a thin collider ("tunnelling"). To prevent it:
Max Linear Speed caps how fast any body may go.
Effectors push bodies around without scripts. Most need a sensor collider on the same entity; they act on bodies inside it.
| Effector | What it does | Key fields |
|---|---|---|
| Platform Effector 2D | One-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 2D | Wind, currents, conveyor zones. | Force Magnitude, Force Angle (0 = right, 90 = up), Force Variation (gusts), Mode (Additive or Target Velocity), Drag, Angular Drag. |
| Point Effector 2D | Attracts 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 2D | Water: floating, drag and currents. | Density, Surface Level, Linear Drag, Angular Drag, Flow Velocity. |
| Constant Force 2D | A constant push or spin every step (rockets, thrusters). | Force (world), Relative Force (body-relative), Torque. |
A ready-made platformer controller. It drives the entity's Rigidbody 2D (Dynamic, usually with Fixed Rotation) and adds ground detection and movement.
| Field | Meaning |
|---|---|
Move Speed, Jump Force | Horizontal speed and jump strength. |
Max Slope Angle | Steeper slopes push the character down and block walking uphill. |
Ground Check Distance, Skin Width, Ground Layer Mask | How the ground is detected (rays from just inside the bottom of the collider). |
Enable Gravity, Gravity Scale | Gravity on the body. |
Stick To Ground | Keeps 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 Settings ▸ Physics (Box2D). Changes take effect the next time you press Play.
| Setting | Default | What it does |
|---|---|---|
| Gravity | — | World gravity. |
| Physics Rate (Hz) | 60 | Fixed steps per second (30–240). 120 or 240 reduces jitter in fast or tightly jointed bodies, at more CPU cost. |
| Sub Steps | 4 | Solver passes inside each step. More makes joints and stacks stiffer. |
| Contact Hertz / Damping / Speed | 30 / 10 / 3 | How firmly overlapping bodies are pushed apart, how damped that is, and the maximum push-out speed (m/s). |
| Restitution Threshold | 1 m/s | Impacts slower than this do not bounce. This is world-wide; Box2D 3.x does not use a per-collider value. |
| Hit Event Threshold | 1 m/s | Impacts faster than this raise hit events. |
| Enable Sleep | on | Resting bodies stop simulating until something wakes them. |
| Contact Softening | off | Softens contacts between very light and very heavy bodies, so a light limb is not shoved around. |
| Max Linear Speed | 400 m/s | Hard speed cap. |
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.
Debug.DrawLine, Debug.DrawBox and Debug.DrawCircle draw shapes for a frame or a duration.Joints, ragdolls and the physics gameplay components (bumpers, portals, conveyors and more) are on the next page: 2D joints, ragdolls & gameplay components.