processingにてイライラ棒をつくりたいのですが、変な部分に当たり判定が生まれてしまいました。
真ん中の線分の上部分です。この当たり判定をなくすためにはどうすればよいでしょうか。
////////////////////////////////////////////////////////////////////////
int radius=40;
void setup() {
size(600, 600);
}
void draw() {
background(255);
stroke(0);
strokeWeight(2);
line(width/4, 0, width/4, 450);
line(width/2, 150, 300, height);
line(width/43, 0, width/43, 450);
fill(150);
if (doesCollide(mouseX, mouseY, width/4, 450)) {
fill(255, 0, 0);
} else if (doesCollide(mouseX, mouseY, 300, height)) {
fill(255, 0, 0);
} else if (doesCollide(mouseX, mouseY, width/43, 450)) {
fill(255, 0, 0);
} else {
fill(100);
}
ellipse(mouseX, mouseY, radius2, radius*2);
}
boolean doesCollide(int x, int y, int xTip, int yTip) {
float d = dist(x, y, xTip, yTip);
if (d <= radius) {
return true;
} else if ((abs(x - xTip) <= radius) && (y <= yTip)) {
return true;
} else {
return false;
}
}
////////////////////////////////////////////////////////////////////////
回答2件