Collision blocks are invisible hitbox identifiers that let Geometry Dash levels detect when two things occupy the same space. By assigning a block ID to objects and then querying whether those IDs are colliding, you can build platform detectors, hit detection, proximity sensors, and other gameplay logic entirely through G.js — no manual trigger wiring required. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/g-js-api/G.js/llms.txt
Use this file to discover all available pages before exploring further.
$block class wraps a numeric block ID and provides helper methods for placing collision block objects and for creating conditional logic based on collision state.
For a higher-level look at how blocks interact with events see /guides/events.
Creating Blocks
block(id)
Creates a $block instance from a known block ID. G.js marks this ID as in-use so it will not be returned by unknown_b().
The GD collision block ID.
$block
unknown_b()
Allocates and returns the next free block ID. Use this whenever you need a collision block but do not need a specific ID.
$block
new $block(a, specific?)
The underlying class constructor. Prefer block() and unknown_b() in everyday code; use the constructor when you need fine-grained control over ID allocation.
The block ID value.
When
true (the default), marks this ID as unavailable for future
unknown_b() allocations.$block is also a named TypeScript export for use in type annotations:
Methods
collision_block(x, y)
Returns a collision block object placed at the given coordinates. Call .add() on the result to insert it into the level.
X coordinate where the collision block object will be placed.
Y coordinate where the collision block object will be placed.
GJsObject
if_colliding(b2, true_id?, false_id?)
Creates a Collision trigger that continuously evaluates whether this block and b2 are overlapping. When they are, true_id is called; when they are not, false_id is called.
The other block to test collision against.
Group to call when the two blocks are colliding. If omitted, nothing happens on collision.
Group to call when the two blocks are not colliding. If omitted, nothing happens when not colliding.
Collision Events
For event-driven (one-shot) collision detection, use thecollision and collision_exit functions from the events module rather than if_colliding. These fire a callback group exactly once when a collision begins or ends.
First collision block.
Second collision block.
When
true, restricts the event to Player 1’s collision block only.When
true, restricts the event to Player 2’s collision block only.P1 and P2 flags are relevant in two-player levels where both players share
the same block ID. Passing P1: true makes the collision event fire only when
Player 1 is involved, preventing false positives from Player 2.