Overlap callback being called multiple times

Hey guys, I have a simple game where when my character crosses a line, he scores a point but the issue is everytime he crosses the line the score increments like 20 times instead of once. I’m using overlap to call upon the scoring function everything the player and the line overlaps. I think it’s because the width of the character calling the overlap to be called for as long as the character is touching it, is there a way to fix this? I just want the function to be called once everytime the character crosses the line.

this.physics.add.overlap(player, scoreBar, scoring, null, this);

function scoring (player, scoreBar)
{
score += 0.5;
scoreText.setText(score);
}

Any help is appreciated!

Disable the collider or disable the scoreBar body.

I can’t disable them because I need the line to stay put

I guess you are looking for an overlapstart event.

Check the example @samme made in topic #1001

var collider = this.physics.add.overlap(player, scoreBar, scoring, null, this);

function scoring (player, scoreBar)
{
  score += 0.5;
  scoreText.setText(score);
  collider.active = false;
}
1 Like