I recommend you look at screenX and implement it
for p5
see Mouse interaction with 3D objects / objects on 3D plane - #2 by Chrisir
In processing JAVA flavor you can say
theX=screenX (.........
theY=screenY (.........
and later
if(dist(mouseX,mouseY,theX,theY)<40) {
// hit
}