Callback in Collider keeps firing

Hiya, this is my first post on this forum so forgive me if I am doing something wrong. I couldn’t find a Collider post that addressed my issue, so I decided to create my own.

My problem is this. I have this simple code here that creates a playerBlock and a npBlocks group, and I want both of these to collide (naturally). Besides that, I want the ‘checkThis()’ function to fire when the collision happens. Keep in mind that npBlocks is an empty group, so there is nothing to collide with at first (I’ll add members through a different function later on)

function create ()
{
    // Non-Player Blocks Group
    npBlocks = this.physics.add.staticGroup();

    // Create player Block
    playBlock = this.physics.add.sprite(160, 16, 'block');
    
    //  Input Events
    cursors = this.input.keyboard.createCursorKeys();

    // Check for Collision:
    this.physics.add.collider(playBlock, npBlocks, checkThis(), null, this);
    playBlock.body.collideWorldBounds = true;
}

However, checkThis() fires as soon as the application starts.

For now, I’ve set checkThis() to just show a console.log message, and that message is displayed immediately at startup:

function checkThis() {
    console.log("Why is this firing?!");
}

Can anyone offer any advice? I am pretty sure I am overlooking something very, veeery simple… :neutral_face:

Hello @CodeCasper and welcome!
Simply delete the parenthesis()

this.physics.add.collider(playBlock, npBlocks, checkThis, null, this);

1 Like

Thank you so much, I can’t believe how simple this was… I knew I’d embarrass myself with my first post :smiley: Thanks again.