CollidePointPoint not guaranteed to detect point-point collisions with default buffer
Matthew-Herman opened this issue · 1 comments
I tried using collidePointPoint in my missile command game @ https://matthew-herman.github.io/personal-website/projects.html, using collidePointPoint without the buffer argument. After pressing spacebar, the aim is to have the blue line terminate when reaching the target white cross. However, using collidePointPoint sometimes does not detect the collision. I coded it as follows:
if (collidePointPoint(this.xPos, this.yPos, this.xTarget, this.yTarget)) {
var index = arrFiredMissiles.indexOf(this);
arrFiredMissiles.splice(index, 1);
arrExplosions.push(new Explosion(this.xPos, this.yPos));
}
I think this is due to the use of floating points. I think this behavior with the default buffer should be explained in the readme because it could cause bugs, which are not easy to trace.
I think what's actually happening is that my object skips over the buffer area, in which collision is supposed to be detected, because it is moving too many pixels per call of draw. So I don't think this is a true problem with the function, but rather due to the fact that my game logic is tied to draw, which only runs 60fps.