Skip to main content

Physics

Tiny Game Engine uses the Rapier physics engine. Two components work together:

  • a Collider gives an object a shape to touch things with;
  • a Physics body makes it part of the physics world: gravity, mass, friction, bouncing.

Shapes added from the + Add menu already have a Collider. A new scene’s Ground has a static Physics body, so things can stand on it.

Collider​

FieldWhat it does
ShapeThe collision shape (see below).
Size / Radius / HeightFor box, sphere and capsule shapes (before the object’s scale).
OffsetMoves the shape relative to the object.
Trigger onlyDetects touches, but things pass through: coins, checkpoints, finish lines, danger zones.
One-way platformFor a static object: things stand on it from above and jump up through it from below, like a platform in a 2D game. A character can also drop down through it (press Down and jump with a Platformer in Side view).
card collider

Collider shapes​

Box
Box
Sphere
Sphere
Capsule
Capsule
ShapeUse for
Automatic (from shape)The default. Follows the visible shape and scale. Models follow their real shape (still objects: exact; moving objects: convex parts).
BoxCrates, walls, platforms.
SphereBalls, round pickups.
CapsuleCharacters — slides smoothly over steps and bumps.
Polygon (2D outline)An outline of this object's own in its X / Y plane, pushed Depth metres deep: a sprite's exact edge, a slope, an L-shaped ledge. Concave outlines keep their shape on moving bodies too. See Polygon collider.
Convex hull (models)One shrink-wrapped hull around a model. Fast; fills in gaps and dents.
Exact mesh (models)Follows every triangle. Best for still scenery: trees, arches, ramps, race tracks.

Turn on Gizmos → Colliders in the viewport toolbar (or Colliders in Play mode) to see them.

Polygon collider​

Like Unity's Polygon Collider 2D. The points belong to the object, so two sprites with the same picture can have different collision: one slime with a tall hit area, another with a small one.

  • Set Shape to Polygon (2D outline). On a sprite it is traced round the drawn pixels of the frame the scene shows (up to 16 points, like Construct's Guess polygon shape); on anything else it starts as a 1 m square.
  • With the object selected, the outline and its points show in the scene view. Drag a point to move it. Double-tap the outline to add a point there. Tap a point and press Delete to remove it (three points stay).
  • The card lists every point as X / Y in metres around the object's origin, before its scale. + Add point adds one on the closing edge, ✨ Fit to sprite traces the sprite's pixels again (after you change its picture, frame or Flip).
  • Depth is how thick it is front to back (0: the sprite's collider depth, else 1 m). Offset moves the whole outline.

A convex outline is one hull. A concave one keeps its notches: a triangle mesh on an object that never moves, one hull per triangle on a moving body or a trigger. Up to 64 points.

In scripts and with Set component: collider { shape: "polygon", points: [[x, y], …], depth }.

Physics body​

Dynamic
Dynamic
Static
Static
Kinematic
Kinematic
TypeBehaves like…
Dynamic (falls, gets pushed)A real object: gravity, collisions, forces. Players, balls, crates, cars.
Static (never moves)Ground, walls, buildings. Cheapest.
Kinematic (moved by logic)Moving platforms, doors, elevators: moved by events/behaviors/tweens, pushes dynamic objects but isn’t pushed.
FieldWhat it does
Mass(Dynamic) Heavier objects push lighter ones.
Friction0 = ice, 1 = rubber.
Bounciness0 = no bounce, 1 = bounces back fully.
Gravity scale(Dynamic) 1 = normal, 0 = floats, 2 = falls fast, negative = rises.
Don’t tip over(Dynamic) Keeps it upright — for characters.
Air drag / Spin drag(Dynamic) Slows moving / spinning over time.
Freeze X / Y / Z(Dynamic) The body cannot move along that axis, like Unity's Freeze Position. Freeze Z to keep a body in one plane for a 2D game.

The world’s gravity is set in Project settings (Earth: 0, −9.82, 0).

Joints​

A Joint component ties this object's physics body to another one, or to the world, like Unity's joints: doors on hinges, a lamp on a chain, a rope bridge, a lift on a rail, a car's wheels. Both objects need a Physics body (the connected one may be static).

A little car on two Wheel joints crossing a rope bridge of planks tied together by Hinge joints

KindTies them so that…
Fixedthey move as one (welded).
Hingethis object turns around Axis through the Anchor: doors, levers, pendulums, bridge planks, a spinning platform. In 2D keep the axis at Z (0, 0, 1).
Ballit swings every way around the anchor: a wrecking ball, a chain link in 3D.
Sliderit only slides along Axis: a lift, a piston, a sliding door.
Springthe two anchors are pulled to Rest length apart, with Stiffness and Damping.
Ropethe anchors can't get further apart than Length (0 = however far apart they start), but can come closer.
Wheel (2D)Unity's Wheel Joint 2D. It goes on the car body, with the wheel as Connected to: the wheel spins freely around Z and rides a spring along the Suspension angle.
FieldWhat it does
Connected toThe other object, or (the world): held where it is when the game starts.
AnchorWhere on this object the joint is, in its own space (before its scale counts: (0.5, 0, 0) on an object 2 wide is its right end). For a Wheel, where the wheel's centre is on the car.
Anchor on other / World pointSpring and Rope: the other end, on the connected object or in the world.
AxisHinge and Slider: what it turns around or slides along, in this object's space.
Limits, Min / MaxHinge: the angles it can turn between (degrees). Slider: how far it can slide (metres).
Suspension angleWheel: the direction the wheel moves up and down along, in the car's X/Y (90 = straight up).
Frequency, Damping ratioWheel: how stiff the suspension is (bounces per second) and how quickly it stops bouncing (0 = keeps bouncing, 1 = no bounce).
Use motor, Motor speed, Max motor forceHinge, Slider, Wheel: a motor drives it at the speed (degrees per second; Slider: metres per second) with at most this force (N·m to turn, N to slide). Positive turns counter-clockwise around the axis (Wheel: the wheel). A weak motor stalls under a heavy load.
Connected collideWhether the two objects still bump into each other.

The Car selected in the 2D view: two Wheel joints, one per wheel, and the line each wheel rides on

Selected, an object shows its joints in the scene view: the anchor (orange), the other end (cyan), the axis, limits and suspension line (purple).

Several joints on one object​

+ Add component → Joint can be added more than once. A rope bridge is a row of planks, each with a Hinge to the plank before it (the first one to the world, at the left bank); the last plank has two Hinges, one to its neighbour and one to the world at the right bank. A car body carries one Wheel joint per wheel.

Joints in events and scripts​

ActionWhat it does
Break jointCuts the object's joints: the rope snaps, the door comes off. They stay cut.
Set joint motorDrives its Hinge, Slider and Wheel joints at Speed with at most Max force (turns the motor on). A speed of 0 holds them still: a brake.
Stop joint motorLets them turn or slide freely again.

Object.jointAngle is a Hinge's angle from where it started (−180 to 180; Slider: metres moved) and Object.jointSpeed how fast it turns (degrees per second). A 2D car driven by the joystick is one event: Every tick → Set joint motor on the car, speed -joystickX * 720 (right is clockwise, so negative).

In scripts: car.setJointMotor(-720, 60), car.stopJointMotor(), door.getJointAngle(), door.getJointSpeed(), rope.breakJoint(). Each takes an optional joint number last (0 = the first Joint component) to act on one joint only.

Collisions in events​

ConditionTrue when…
⚡ On collision withthe object starts touching another (once per touch).
⚡ On collision endedit stops touching.
Is touchingit is touching right now (every frame).
Is on groundit stands on something.
Has line of sight tonothing solid is between it and another object.
Seesthe other object is in its Sight cone and nothing solid is in between.
⚡ On starts seeing / ⚡ On loses sight ofthat changes (once each time).
Raycast / Raycast froman invisible ray hits something solid (see Raycasts).

Actions: Set velocity, Push (impulse) (a kick), Apply force (a push over time), Jump. In scripts: entity.applyImpulse(0, 5, 0), game.raycast(from, to) (see Raycasts). See the Conditions and Actions reference.

Common problems
  • Falls through the floor — the floor needs a Collider (and a static body); very fast small objects may need a bigger collider.
  • Doesn’t move — a behavior like Platformer or Car needs a dynamic body.
  • Rolls over / tips — tick Don’t tip over.
  • Coins block the player — tick Trigger only on the coin’s collider.

Sight​

Give a guard, a turret or a camera a Sight component to say what it can see: how far, how wide, and from where. The Sees condition and entity.canSee() then check that the target is inside that cone and that no wall is in the way.

SettingWhat it does
RangeHow far it sees, in metres. 0 is no limit.
View AngleHow wide the cone is, in degrees, from edge to edge. 360 sees all round. The cone is as tall as it is wide.
EyeWhere it looks from, measured from the object's origin in its own directions. Raise it to the head (Y 1.6 on a character).
card sight

The cone points the way the object faces (its −Z, like every object here), so turning the guard turns its view.

Select the object to see its cone (seen here from the top). Gizmos → Sight cones hides it.
Select the object to see its cone (seen here from the top). Gizmos → Sight cones hides it.

Example: a guard that notices the player

  1. Add Sight to the Guard. Set Range 12 and View Angle 90.
  2. Event: Guard sees Player → Set Guard.Alert to 1 (or play a sound, chase…).
  3. Walls and crates with colliders hide the player. Triggers (coins, checkpoints) don't block sight.

Sees is true every frame the guard sees the player. To react once, use the triggers:

  • ⚡ On Guard starts seeing Player → play a "!" sound, start chasing.
  • ⚡ On Guard loses sight of Player → go back to patrolling after a while.

They don't fire when the player is destroyed.

In scripts:

if (guard.canSee(player)) guard.lookAt(player.position);
turret.canSee(player, { range: 20, angle: 40 }); // other limits than its Sight component

game.watchSight('Player'); // the triggers for scripts:
game.on('seen', ({ entity, target }) => entity.setVar('Alert', 1));
game.on('lostSight', ({ entity, target }) => entity.setVar('Alert', 0));

Without a Sight component, canSee has no range or angle limit: it only checks for walls, like Has line of sight to.

Raycasts​

A raycast shoots an invisible ray and tells you what it hit first. Use it for a gun that hits what it aims at, a character that checks the ground or a wall ahead, or an enemy that looks for the player. Triggers (coins, checkpoints) never block a ray.

Two conditions in the Physics group:

ConditionThe ray starts…
Raycast from (on an object)at the object, going forward, backward, left, right, up or down. Start height lifts it, for example to eye level. It never hits the object itself.
Raycast (no object)at any point (X, Y, Z) and goes in any direction (X, Y, Z), for Length meters.

Both have three optional filters: Must hit (true only when the ray hits that kind of object, and it becomes the picked object for the actions), Only tag (ignore everything without that tag) and Ignore (objects the ray passes through).

When the condition is true, the actions of the same event can read what was hit:

ValueMeaning
rayhitname()the name of the object that was hit
rayHitX, rayHitY, rayHitZwhere it hit
rayNormalX, rayNormalY, rayNormalZwhich way the surface faces (rayNormalY is 1 on flat ground)
rayDistancehow far the ray travelled, in meters

In scripts, the same thing is game.raycast(from, to) or, along a direction:

const hit = game.raycast(entity.position, {
direction: entity.getForward(), // any direction
length: 20, // default 100
tags: ['enemy'], // optional: only objects with this tag
ignore: entity, // optional: pass through these (and their children)
includeMoving: true, // false = only static scenery
});
if (hit) console.log(hit.entity.name, hit.distance, hit.point, hit.normal);

It returns { entity, point, normal, distance }, or null when nothing was hit.