Krotox Engine › Docs › Krotox Manual › 2D Physics

2D joints, ragdolls & physics gameplay components

Connecting bodies with Box2D joints (distance, hinge, slider, wheel, weld, motor, target, friction), breakable joints, building ragdolls, and the ready-made gameplay components: spawners, bumpers, force fields, portals, conveyors, hazards, motion paths and level metadata.

Joints

A joint connects two bodies and limits how they can move relative to each other. Add the joint component to one entity and set Connected Entity to the other. Both need a Rigidbody 2D.

Fields most joints share:

FieldMeaning
Connected EntityThe other body.
Anchor A / Anchor BWhere the joint attaches on each body, in that body's local space.
Collide ConnectedWhether the two connected bodies still collide with each other. Usually off.
Enable Break Force / Break ForceBreak the joint when it is pulled harder than this (newtons). Default 1000.
Enable Break Torque / Break TorqueBreak it when twisted harder than this.

Joint types

JointKeepsKey fieldsUse it for
Distance Joint 2DA distance between two pointsLength (default 1), Auto Length, Enable Spring + Hertz (4) and Damping Ratio (0.5), Enable Limit + Min / Max LengthRopes, chains, springy connections, swinging lamps.
Hinge Joint 2DA shared pivot pointEnable Limit + Lower / Upper Angle, Enable Motor + Motor Speed and Max Motor Torque, Enable Spring + Target AngleDoors, pendulums, flippers, ragdoll joints, spinning traps.
Slider Joint 2DMovement along one axisAxis (default 1, 0), Enable Limit + Lower / Upper Translation, Enable Motor + Motor Speed and Max Motor Force, Enable Spring + Target TranslationPistons, elevators, sliding doors, rails.
Wheel Joint 2DA wheel on suspensionAxis (default 0, 1), Enable Spring + Hertz and Damping Ratio (0.7), Enable Motor + Motor Speed and Max Motor Torque, Enable LimitVehicle wheels.
Weld Joint 2DBoth bodies locked togetherLinear Hertz, Angular Hertz, Linear / Angular Damping Ratio (0 hertz is fully rigid)Gluing pieces that can break apart.
Motor Joint 2DOne body driven relative to anotherLinear Velocity, Angular Velocity, Max Velocity Force / Torque, spring settingsDriving a body toward a pose; moving platforms that carry riders.
Target Joint 2DA point pulled toward a world targetTarget, Anchor, Max Force (1000), Hertz (5), Damping Ratio (0.7). No connected entity.Dragging objects with a finger or the mouse.
Friction Joint 2DResistance to relative motionMax Force (50), Max Torque (10)Top-down games: objects that slide to a stop on the "floor".

Breakable joints

With a break force or torque enabled, the joint snaps when the load passes the threshold, and the script on the entity receives OnJointBreak2D. Scripts can also break a joint on purpose with Break(), and read the live ReactionForce and ReactionTorque.

Driving motors from scripts

Motor speed, maximum torque or force, and spring targets can be set from a script every frame. They update the running joint in place, so the motion stays smooth. Enable the motor or spring first (in the inspector or once with SetMotor). See driving joint motors.

Building a ragdoll

  1. Make one entity per bone (torso, head, upper and lower arms and legs), each with a Rigidbody 2D (Dynamic) and a collider.
  2. Join neighbouring bones with Hinge Joint 2Ds at the shoulders, elbows, hips and knees. Use Distance Joint 2D for rigid links.
  3. Turn on angle limits so elbows and knees only bend one way.
  4. Keep Collide Connected off on every joint.
  5. Give every bone's Rigidbody 2D the same negative Collision Group, so limbs never collide with each other but still hit the world.

If a falling chain jitters, raise Physics Rate in the project settings, then try Contact Softening.

For limbs that should reach a target (a hand toward a ledge, feet on uneven ground), InverseKinematics2D.SolveTwoBone works out the angles from a script; feed them to the hinges' TargetAngle.

Physics gameplay components

Ready-made behaviours that run inside the physics step. Add them from Add Component ▸ Physics Gameplay. They are configured in the inspector and scripts can change them while the game runs.

Force Field Zone, Portal, Hazard Zone and Proximity Trigger read who is inside them from a sensor collider on the same entity: tick Is Sensor or they do nothing. Physics Bumper and Surface Conveyor use solid contacts, so their colliders must not be sensors.
ComponentWhat it doesKey fields
SpawnerReleases a prefab on a timer.Spawn Prefab; Spawn Interval (1 s) with jitter; Max Ammo (-1 = unlimited); Max Simultaneous (0 = unlimited); Launch Velocity with speed and angle jitter; Sweep (horizontal, vertical or circular oscillation); optional charge (an idle spawner fires an over-charged shot) and overheat (heat builds per shot and jams the spawner).
Physics BumperKicks bodies that hit it.Mode: Radial (away from the centre, a pinball bumper) or Directional (along Direction, a launch pad); Impulse Strength (8); Retrigger Delay (0.1 s); Scale Punch (a squash on impact); impact sound.
Force Field ZoneWind or a radial push or pull inside the zone.Mode: Directional (along Force) or Radial (negative strength pulls in); Ignore Mass (everything accelerates equally, like gravity); Falloff With Distance; Oscillate for gusts. Draws arrows over the zone in the Viewport.
PortalTeleports bodies to a linked portal.Linked Portal (links are one-way: set the partner's link back for a pair); Reorient Velocity; Preserve Speed; Minimum Entry Speed; Exit Offset; Reentry Cooldown (0.25 s, which stops a pair ping-ponging a body).
Surface ConveyorCarries bodies along its surface.Surface Speed (3, along the entity's local +X: rotate the entity to rotate the belt); Match Target Velocity; Acceleration; Affect Vertical Axis; Reverse.
Hazard ZoneReacts when something enters.On Enter: Destroy Entity, Respawn At Start, Reload Scene or Event Only; Target Tag (empty affects everything, which is rarely what you want); Trigger Delay; optional effect prefab and sound.
Proximity TriggerRewards near misses around a hazard.Core Hazard (touching it disqualifies the graze); Graze Score (100); Score Multiplier; Award On Exit; Highlight Visitor with a tint. Reports through OnTriggerEnter / OnTriggerExit.

Runtime state on these components (timers, heat, jams, graze counts) resets when you stop Play.

Motion Path

Moves or rotates an entity on a loop, with no script: moving platforms, swinging blades, rotating obstacles, doors.

FieldDefaultMeaning
TypeLinear Ping PongLinear Ping Pong (A to B and back), Linear Loop, Continuous Rotation, Oscillating Swing or Move And Rotate.
Point A, Point B—The two ends of a linear path.
EasingSmooth StepLinear, Ease In Out Quad, Ease In Out Cubic, Smooth Step or Bounce.
Speed2Movement speed.
Pause Duration At Ends0.2 sWait at each end.
Rotation Speed90 °/sFor the rotating types.
Swing Angle Min / Max-45° / 45°Range of an oscillating swing.
Phase Offset0Start partway through, so several platforms move out of step.
Pivot Offset—The hinge for rotating types. Drag the magenta pivot handle in the Viewport.

Level metadata

The Level Metadata component describes a level: Level Index, Level Name, Chapter Name, Target Score (100), Time Limit Seconds (60), Required Collectibles (3), the Next Level Scene and Auto Load Next On Victory. It also has three star conditions, each with a score, a time and a collectible count:

StarDefault condition
1Complete the level (100 points within 120 s)
2Beat the par time (250 points within 60 s, 2 collectibles)
3Collect everything (500 points within 45 s, 3 collectibles)

Edit it inline with Level Data on the toolbar's Level Stepper. Scripts call EvaluateStars(score, elapsed, collectibles) at the end of a level to get 0 to 3 stars.