I'm trying to check if one sprite is passing the line between two other sprites. I tried to check if the sprite is overlapping a Phaser.Line with:
this.lineGreenToRed = new Phaser.Line(this.ballGreen.x, this.ballGreen.y, this.ballRed.x, this.ballRed.y);
this.checkPassed = this.lineGreenToRed.pointOnLine(this.ballBlue.position.x, this.ballBlue.position.y);
if (this.checkPassed) {
console.log('GreenToRed passed');
//counter++;
};
console.log(this.checkPassed);
Looking into the console this counts up the false events whenever my sprite is not on/over the line. Moving it over the line sometimes gives me the true event, but not always. It looks like the frames change too fast to detect it. Overlap check on Lines does not seem to be possible neither.
I have also tried with:
this.GreenToRedArray = this.lineGreenToRed.coordinatesOnLine();
and in update():
this.GreenToRedArray.forEach(this.checkPoint, this);
and then:
checkPoint : function(element){
if (this.ballBlue.position.x == element[0] && this.ballBlue.position.y == element[1]){
console.log('GreenToRed passed');
this.score++;
console.log(this.score);
this.scoreText.setText(this.score);
}
},
This works as long as I move quite slow over the line, but as soon as things move a little faster, it does not catch it anymore.
Any hint on how I could check if one sprite is moving over the line between two other sprites?
Think of it as two balls marking kind of a goal and a third ball being shoot through between these two.
Thanks a lot for any help.