Physics and collisions

Falling, jumping, moving, and bumping into things: the simple physics a Minimo game can use.

Try each example, then copy the words under it and paste them to your AI. You can also send your AI the link to an example.

Motion

Objects that move by themselves once the game gives them a push or a pull.

Gravity

Pulls objects down, faster and faster, until they land on something solid.

1400
Ask your AI

Make the ball fall with 1400 gravity and land on the ground.

View code
game.physics = true;
game.gravityY = 1400;
ball.gravityScale = 1;
// every frame:
game.collide(ball, ground);

Speed and direction

An object keeps moving at the speed it was given, like a puck on ice.

260px/s
Ask your AI

Make the ball move on its own and bounce off the edges of the screen.

View code
ball.vx = 260;
ball.vy = 260;
// every frame:
if (ball.x < 0 || ball.x > game.width) ball.vx *= -1;
if (ball.y < 0 || ball.y > game.height) ball.vy *= -1;

Jump

A push upward that gravity then brings back down. The player can only jump again once they have landed.

Tap to jump.

800
1800
Ask your AI

When the player taps, make the character jump, but only if it is standing on the ground.

View code
const hit = game.collide(ball, ground);
if (hit?.grounded && game.isPointerPressed()) {
  ball.vy = -800;
}

Contact

What happens when two objects meet.

Touch or bump

Touching is for collecting and scoring: things pass through each other. Bumping is for walls and floors: things stop.

Ask your AI

Make the bar solid, so the ball lands on it and stops.

View code
bar.isStatic = true;
game.collide(ball, bar);

Collision box

Collisions use an invisible box, not the drawing itself. A box as big as the picture makes hits feel unfair, because corners touch before the shapes do.

100%
Ask your AI

Make the ball's collision box 100% of its picture, so hits only count when the shapes really touch.

View code
ball.bodyWidth = ball.width * 100 / 100;
ball.bodyHeight = ball.height * 100 / 100;
game.debugBodies = true; // shows the boxes while testing