Skip to content

collidePointPoint()

Ben Moren edited this page Jun 5, 2021 · 1 revision
collidePointPoint(x, y, x2, y2, [buffer])

Point to point collision with an optional buffer zone.

Live example

var hit = false;

function draw() {
    background(255);
    circle(100, 100, 1);       // change to 10,10px size for buffer example
    circle(mouseX, mouseY, 1); // change to 10,10px size for buffer example

    // No buffer zone, most standard example:
    hit = collidePointPoint(100, 100, mouseX, mouseY);

    // Buffer of 10 px:
    // hit = collidePointPoint(100, 100, mouseX, mouseY, 10);

    // Use vectors as input:
    // const p1    = createVector(100, 100);
    // const mouse = createVector(mouseX, mouseY);
    // hit = collidePointPointVector(p1, mouse, 10);

    stroke(hit ? color('red') : 0);
    print('colliding?', hit);
}